From e41de6bfff86e2398064288204e5de33863af24c Mon Sep 17 00:00:00 2001 From: Anton Date: Wed, 31 Jan 2024 14:01:30 +0300 Subject: [PATCH] fix(Autocomplete): keyboard navigation --- .../AutoComplete/AutoComplete.stories.tsx | 39 ++++++++++++++----- src/components/Checkbox/Checkbox.stories.tsx | 4 +- src/components/Checkbox/Checkbox.tsx | 20 +++------- src/components/FilterCheckbox.tsx | 2 +- .../AutoComplete/AutoComplete.stories.tsx | 35 +++++++++++++---- src/harmony/Checkbox/Checkbox.stories.tsx | 8 ++-- src/harmony/Checkbox/Checkbox.tsx | 33 ++++++---------- 7 files changed, 82 insertions(+), 59 deletions(-) diff --git a/src/components/AutoComplete/AutoComplete.stories.tsx b/src/components/AutoComplete/AutoComplete.stories.tsx index 0fef93a3..7df0fb43 100644 --- a/src/components/AutoComplete/AutoComplete.stories.tsx +++ b/src/components/AutoComplete/AutoComplete.stories.tsx @@ -34,6 +34,16 @@ const data: Items = Array.from({ length: 1000 }, (_, i) => { }; }); +interface FocusableItemProps extends React.HTMLAttributes { + focused?: boolean; +} + +const FocusableItem: React.FC = ({ focused, children, style = {}, ...attr }) => ( +
+ {children} +
+); + export const Single: StoryFn = (args) => { const [value, setValue] = useState(''); const [list, setList] = useState([]); @@ -52,7 +62,16 @@ export const Single: StoryFn = (args) => { items={list} onChange={args.onChange} keyGetter={(item) => item.id} - renderItem={(props) =>
{`${props.item.id}: ${props.item.title}`}
} + renderItem={(props) => ( + + {`${props.item.id}: ${props.item.title}`} + + )} > = (args) => { onChange={args.onChange} keyGetter={(item) => item.id} renderItem={(props) => ( -
+ {props.item.id}: {props.item.title} -
+ )} > = (args) => { onChange={args.onChange} keyGetter={(item) => item.id} renderItem={(props) => ( -
+ -
+ )} > = (args) => ( items={finiteList} value={finiteList.slice(2, 4)} renderItem={(props) => ( - - - {props.item.title} - + + + + {props.item.title} + + )} > diff --git a/src/components/Checkbox/Checkbox.stories.tsx b/src/components/Checkbox/Checkbox.stories.tsx index 467d67f3..82a61633 100644 --- a/src/components/Checkbox/Checkbox.stories.tsx +++ b/src/components/Checkbox/Checkbox.stories.tsx @@ -18,10 +18,10 @@ export const Default: StoryFn = (args) => ( <> Checkbox - + - + Checkbox diff --git a/src/components/Checkbox/Checkbox.tsx b/src/components/Checkbox/Checkbox.tsx index d99f781f..3c4ef705 100644 --- a/src/components/Checkbox/Checkbox.tsx +++ b/src/components/Checkbox/Checkbox.tsx @@ -36,28 +36,20 @@ export const CheckboxLabel: React.FC { value: string; - checked: boolean; + checked?: boolean; + defaultChecked?: boolean; } -export const CheckboxInput = forwardRef(({ value, checked, ...attrs }, ref) => ( +export const CheckboxInput = forwardRef(({ value, ...attrs }, ref) => ( {({ id, onClick, name }) => ( - + )} )); export const Checkbox = forwardRef>( - ({ onClick, name, className, children }, ref) => { + ({ onClick, name, className, children, ...attr }, ref) => { const handleOnChange = useCallback>((event) => { onClick(event.target.value); }, []); @@ -66,7 +58,7 @@ export const Checkbox = forwardRef - + {children} diff --git a/src/components/FilterCheckbox.tsx b/src/components/FilterCheckbox.tsx index dce0a709..4fbc1a02 100644 --- a/src/components/FilterCheckbox.tsx +++ b/src/components/FilterCheckbox.tsx @@ -32,7 +32,7 @@ interface FilterCheckboxProps extends CheckboxProps { export const FilterCheckbox: React.FC = ({ name, onClick, checked, value, label, iconLeft }) => ( - + {nullable(iconLeft, (icon) => icon)} diff --git a/src/harmony/AutoComplete/AutoComplete.stories.tsx b/src/harmony/AutoComplete/AutoComplete.stories.tsx index 1788a80a..77a1b9b9 100644 --- a/src/harmony/AutoComplete/AutoComplete.stories.tsx +++ b/src/harmony/AutoComplete/AutoComplete.stories.tsx @@ -33,6 +33,16 @@ const data: Items = Array.from({ length: 1000 }, (_, i) => { }; }); +interface FocusableItemProps extends React.HTMLAttributes { + focused?: boolean; +} + +const FocusableItem: React.FC = ({ focused, children, style = {}, ...attr }) => ( +
+ {children} +
+); + export const Single: StoryFn = (args) => { const [value, setValue] = useState(''); const [list, setList] = useState([]); @@ -51,7 +61,14 @@ export const Single: StoryFn = (args) => { items={list} onChange={args.onChange} keyGetter={(item) => item.id} - renderItem={(props) =>
{`${props.item.id}: ${props.item.title}`}
} + renderItem={(props) => ( + {`${props.item.id}: ${props.item.title}`} + )} > = (args) => { onChange={args.onChange} keyGetter={(item) => item.id} renderItem={(props) => ( -
= (args) => { name="item" label={`${props.item.id}: ${props.item.title}`} /> -
+ )} > = (args) => { onChange={args.onChange} keyGetter={(item) => item.id} renderItem={(props) => ( -
+ -
+ )} > = (args) => ( items={finiteList} value={finiteList.slice(2, 4)} renderItem={(props) => ( -
+ = (args) => ( value={props.item.id} label={props.item.title} /> -
+ )} > diff --git a/src/harmony/Checkbox/Checkbox.stories.tsx b/src/harmony/Checkbox/Checkbox.stories.tsx index e12ef634..310d8acd 100644 --- a/src/harmony/Checkbox/Checkbox.stories.tsx +++ b/src/harmony/Checkbox/Checkbox.stories.tsx @@ -16,9 +16,9 @@ export default { export const Default: StoryFn = (args) => ( <> - + - + ); @@ -26,9 +26,9 @@ export const Default: StoryFn = (args) => ( export const Labeled: StoryFn = (args) => { return (
- + - +
); diff --git a/src/harmony/Checkbox/Checkbox.tsx b/src/harmony/Checkbox/Checkbox.tsx index 3e2c5133..bae17051 100644 --- a/src/harmony/Checkbox/Checkbox.tsx +++ b/src/harmony/Checkbox/Checkbox.tsx @@ -9,24 +9,15 @@ interface CheckboxProps extends React.InputHTMLAttributes { label?: React.ReactNode; } -export const Checkbox = forwardRef( - ({ checked, label, className, disabled, ...rest }, ref) => ( - - ), -); +export const Checkbox = forwardRef(({ label, className, disabled, ...rest }, ref) => ( + +));