import "./ChoicesSelect"; import { Meta, StoryObj } from "@storybook/react-vite"; import { expect, fn, userEvent, waitFor, within } from "storybook/test"; import { iconClass } from "../../../../utils/iconClass"; import { useValue } from "../../../__fixtures__/useValue.hook"; import { Select } from "../Select"; const options = [ { label: "Option 1", value: "option-1" }, { label: "Option 2", value: "option-2" }, { label: "Option 3", value: "option-3" } ]; const OptionTemplate = ({ label, data }: any) => { return ( {label} {data?.hint} ); }; async function openChoicesDropdown(canvasElement: HTMLElement) { await waitFor(() => { expect(canvasElement.querySelector(".choices")).toBeInTheDocument(); }); const choicesElement = canvasElement.querySelector(".choices") as HTMLElement; const inner = choicesElement.querySelector(".choices__inner") as HTMLElement; await userEvent.click(inner); await waitFor(() => { expect(choicesElement.classList.contains("is-open")).toBe(true); }); return choicesElement; } function sleep(ms = 300) { return new Promise((resolve) => setTimeout(resolve, ms)); } /** * ChoicesJS select component. * * ```tsx * import {Select} from "@tsed/react-formio/molecules/forms/select/all"; // import HTML5, ChoicesJS and React components * * // or * import {Select} from "@tsed/react-formio/molecules/forms/select/Select"; * import "@tsed/react-formio/molecules/forms/select/components/ChoicesSelect"; // register only ChoicesJS component * * ``` */ export default { title: "forms/Select/ChoiceJs", component: Select, parameters: { layout: "centered", backgrounds: { default: "pearl" }, docs: { description: { component: "Choices.js layout using the v11 template callback API. Custom option renderers should be passed with `customProperties.template` on each option to keep Choices `data-*` and ARIA attributes intact." } } }, args: { layout: "choicesjs" }, argTypes: { label: { control: "text" }, name: { control: "text" }, value: { control: "text" }, size: { control: "radio", options: ["small", "normal"] }, placeholder: { control: "text" }, options: { control: "object" }, onChange: { action: "onChange" } }, tags: ["autodocs"], render(args) { // eslint-disable-next-line react-hooks/rules-of-hooks const { value, onChange } = useValue(args); return (