Skip to content

Commit

Permalink
fix: visible, non-interactive elements with click handlers must have …
Browse files Browse the repository at this point in the history
…at least one keyboard listener
  • Loading branch information
physicsSorcererKing committed May 5, 2024
1 parent a81f754 commit 05d8e60
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 deletions components/shared/Icon/v2/icon.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { Meta, StoryObj } from "@storybook/react";
import { useState } from "react";
import { MouseEventHandler, useState } from "react";

import IconV2 from ".";
import icons from "./icons";
Expand Down Expand Up @@ -39,14 +39,18 @@ const AllIcons = () => {
const [value, setValue] = useState("");
const toast = useToast();

const handleClick = (iconName: string) => () => {
const cb = navigator.clipboard;
const text = `<IconV2 name="${iconName}" className="w-6 h-6" />`;
const handleClick =
(iconName: string): MouseEventHandler<HTMLButtonElement> =>
(e) => {
e.stopPropagation();

toast({ children: "已複製成功!!" }, { duration: 1000 });
const cb = navigator.clipboard;
const text = `<IconV2 name="${iconName}" className="w-6 h-6" />`;

cb.writeText(text).then();
};
toast({ children: "已複製成功!!" }, { duration: 1000 });

cb.writeText(text).then();
};

return (
<>
Expand All @@ -67,7 +71,7 @@ const AllIcons = () => {
{keys(icons)
.filter((iconName) => iconName.includes(value))
.map((iconName) => (
<div
<button
key={iconName}
className="cursor-pointer"
onClick={handleClick(iconName)}
Expand All @@ -76,7 +80,7 @@ const AllIcons = () => {
<p className="text-center text-white/90 whitespace-nowrap">
{iconName}
</p>
</div>
</button>
))}
</div>
</>
Expand Down

0 comments on commit 05d8e60

Please sign in to comment.