fix: select tests
This commit is contained in:
parent
290d708b12
commit
b39092c21c
@ -40,6 +40,22 @@ const Select = forwardRef(
|
||||
{ label, placeholder, value, options, required = false, disabled, onChange }: SelectProps,
|
||||
ref: Ref<HTMLButtonElement>,
|
||||
) => {
|
||||
const { width } = useElementSize<HTMLButtonElement>(ref);
|
||||
|
||||
const [open, setOpen] = useState(false);
|
||||
const debouncedOpen = useDebounce(open, 200);
|
||||
const handleOpenChange = useCallback(
|
||||
(newOpen: boolean) => {
|
||||
if (debouncedOpen !== open) {
|
||||
return;
|
||||
}
|
||||
|
||||
setOpen(newOpen);
|
||||
},
|
||||
[debouncedOpen, open],
|
||||
);
|
||||
const handleButtonClick = useCallback(() => handleOpenChange(!open), [handleOpenChange, open]);
|
||||
|
||||
const handleChange = useCallback(
|
||||
(_event: MouseEvent | KeyboardEvent | FocusEvent | null, selectedValue: number | string) => {
|
||||
if (Array.isArray(value)) {
|
||||
@ -52,31 +68,16 @@ const Select = forwardRef(
|
||||
}
|
||||
|
||||
onChange(newValue);
|
||||
setOpen(false);
|
||||
return;
|
||||
}
|
||||
|
||||
onChange(selectedValue);
|
||||
setOpen(false);
|
||||
},
|
||||
[onChange, value],
|
||||
);
|
||||
|
||||
const { width } = useElementSize<HTMLButtonElement>(ref);
|
||||
|
||||
const [open, setOpen] = useState(false);
|
||||
const debouncedOpen = useDebounce(open, 250);
|
||||
const handleOpenChange = useCallback(
|
||||
(newOpen: boolean) => {
|
||||
if (debouncedOpen !== open) {
|
||||
return;
|
||||
}
|
||||
|
||||
setOpen(newOpen);
|
||||
},
|
||||
[debouncedOpen, open],
|
||||
);
|
||||
|
||||
const handleButtonClick = useCallback(() => handleOpenChange(!open), [handleOpenChange, open]);
|
||||
|
||||
return (
|
||||
<div className="relative w-full">
|
||||
{/* eslint-disable-next-line @typescript-eslint/no-explicit-any */}
|
||||
|
@ -2,8 +2,8 @@
|
||||
* @jest-environment jsdom
|
||||
*/
|
||||
import '@testing-library/jest-dom';
|
||||
import userEvent from '@testing-library/user-event';
|
||||
import { act } from '@testing-library/react';
|
||||
import userEvent from '@testing-library/user-event';
|
||||
|
||||
import { mockSelectField } from '@staticcms/test/data/fields.mock';
|
||||
import { createWidgetControlHarness } from '@staticcms/test/harnesses/widget.harness';
|
||||
|
@ -70,6 +70,7 @@ export const createMockWidgetControlProps = <
|
||||
i18n: undefined,
|
||||
duplicate: false,
|
||||
hidden: false,
|
||||
controlled: false,
|
||||
theme: 'light',
|
||||
onChange: jest.fn(),
|
||||
openMediaLibrary: jest.fn(),
|
||||
|
Loading…
x
Reference in New Issue
Block a user