Skip to content

Commit

Permalink
chore: ally 테스트 통과하기 위해
Browse files Browse the repository at this point in the history
  • Loading branch information
eugene028 committed May 25, 2024
1 parent 2acd9e0 commit d070f9e
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
1 change: 1 addition & 0 deletions packages/wow-ui/src/components/Chip/Chip.stories.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ export const CanDelete: Story = {
label: "Chip",
variant: "default",
onDelete: () => {
// eslint-disable-next-line no-undef
console.log("삭제합니다.");
},
},
Expand Down
19 changes: 13 additions & 6 deletions packages/wow-ui/src/components/Chip/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import { cva } from "@styled-system/css";
import { styled } from "@styled-system/jsx";
import type { ElementType, MouseEvent, ReactNode } from "react";
import { forwardRef, useEffect, useState } from "react";
import { forwardRef, useEffect, useRef, useState } from "react";

import CloseButton from "@/components/Chip/closeButton";
import type {
Expand Down Expand Up @@ -81,6 +81,7 @@ const Chip: ChipComponent = forwardRef(
const [isActived, setIsActive] = useState(() =>
isSelected ? isSelected : defaultSelected
);
const closeButtonRef = useRef<HTMLDivElement>(null);

useEffect(() => {
if (isSelected !== undefined) {
Expand All @@ -102,10 +103,10 @@ const Chip: ChipComponent = forwardRef(
if (!clickable) return;
if (event.currentTarget === event.target) {
event.preventDefault();
}
if (event.key === "Enter" || event.key === " ") {
setIsActive((prev) => !prev);
onKeyDown?.();
if (event.key === "Enter" || event.key === " ") {
setIsActive((prev) => !prev);
onKeyDown?.();
}
}
};

Expand All @@ -124,7 +125,13 @@ const Chip: ChipComponent = forwardRef(
>
<ChipLabel isActived={isActived} label={label} variant={variant} />
{onDelete ? (
<div onClick={handleDeleteButtonClick}>
<div
ref={closeButtonRef}
role="button"
tabIndex={0}
onClick={handleDeleteButtonClick}
onKeyDown={onDelete}
>
<CloseButton color={isActived ? "#ffffff" : "#8f8f8f"} size={14} />
</div>
) : null}
Expand Down

0 comments on commit d070f9e

Please sign in to comment.