@moda/om 21.6.9 → 21.6.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs.js +126 -70
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.esm.js +125 -71
- package/dist/index.esm.js.map +1 -1
- package/dist/src/components/Field/FormControlContext.d.ts +6 -0
- package/dist/src/components/Field/index.d.ts +1 -0
- package/dist/src/components/Select/SelectLabel.d.ts +1 -1
- package/dist/src/components/Select/SelectOption.d.ts +1 -0
- package/dist/src/components/Select/useSelect.d.ts +1 -0
- package/dist/styles.css +1 -1
- package/package.json +1 -1
- package/src/components/Field/Field.tsx +46 -41
- package/src/components/Field/FormControlContext.tsx +11 -0
- package/src/components/Field/index.ts +1 -0
- package/src/components/Select/MultiSelect.tsx +20 -2
- package/src/components/Select/Select.scss +4 -0
- package/src/components/Select/Select.test.tsx +24 -10
- package/src/components/Select/Select.tsx +28 -6
- package/src/components/Select/SelectLabel.tsx +7 -2
- package/src/components/Select/SelectOption.tsx +4 -1
- package/src/components/Select/SelectOptions.tsx +7 -2
- package/src/components/Select/useSelect.ts +7 -4
|
@@ -7,6 +7,7 @@ import { SelectableOption } from './Select';
|
|
|
7
7
|
import './SelectOption.scss';
|
|
8
8
|
|
|
9
9
|
export type SelectOptionProps = Omit<React.HTMLAttributes<HTMLLIElement>, 'onClick'> & {
|
|
10
|
+
id?: string;
|
|
10
11
|
active: boolean;
|
|
11
12
|
selected: boolean;
|
|
12
13
|
option: SelectableOption;
|
|
@@ -15,6 +16,7 @@ export type SelectOptionProps = Omit<React.HTMLAttributes<HTMLLIElement>, 'onCli
|
|
|
15
16
|
};
|
|
16
17
|
|
|
17
18
|
export const SelectOption: React.FC<SelectOptionProps> = ({
|
|
19
|
+
id,
|
|
18
20
|
active,
|
|
19
21
|
selected,
|
|
20
22
|
option,
|
|
@@ -42,6 +44,7 @@ export const SelectOption: React.FC<SelectOptionProps> = ({
|
|
|
42
44
|
|
|
43
45
|
return (
|
|
44
46
|
<li
|
|
47
|
+
id={id}
|
|
45
48
|
ref={ref}
|
|
46
49
|
className={classNames('SelectOption', className, {
|
|
47
50
|
'SelectOption--active': active,
|
|
@@ -50,8 +53,8 @@ export const SelectOption: React.FC<SelectOptionProps> = ({
|
|
|
50
53
|
})}
|
|
51
54
|
onClick={handleClick}
|
|
52
55
|
data-test-id={dataTestId ? `${dataTestId}--${label.replace(' ', '-')}` : undefined}
|
|
53
|
-
aria-label={label}
|
|
54
56
|
aria-selected={selected}
|
|
57
|
+
aria-disabled={disabled || undefined}
|
|
55
58
|
role='option'
|
|
56
59
|
>
|
|
57
60
|
{colorSwatch && (
|
|
@@ -78,12 +78,17 @@ export const SelectOptions: React.FC<SelectOptionsProps> = ({
|
|
|
78
78
|
)}
|
|
79
79
|
|
|
80
80
|
<ul
|
|
81
|
+
id={`Select__listbox--${idRef}`}
|
|
81
82
|
className='SelectOptions__list'
|
|
82
83
|
tabIndex={-1}
|
|
83
84
|
role='listbox'
|
|
84
85
|
ref={ref}
|
|
85
|
-
aria-
|
|
86
|
-
aria-activedescendant={
|
|
86
|
+
aria-label='Options'
|
|
87
|
+
aria-activedescendant={
|
|
88
|
+
activeOption
|
|
89
|
+
? `SelectOption--${activeOption.value}${idRef ? `-${idRef}` : ''}`
|
|
90
|
+
: undefined
|
|
91
|
+
}
|
|
87
92
|
{...rest}
|
|
88
93
|
>
|
|
89
94
|
{options.map(option => (
|
|
@@ -19,12 +19,12 @@ type Action =
|
|
|
19
19
|
| { type: 'SELECT'; payload: { value: string | string[] } }
|
|
20
20
|
| { type: 'FOCUS'; payload: { value: string } };
|
|
21
21
|
|
|
22
|
-
const reducer = (state: State, action: Action) => {
|
|
22
|
+
const reducer = (state: State, action: Action): State => {
|
|
23
23
|
switch (action.type) {
|
|
24
24
|
case 'OPEN':
|
|
25
25
|
return { ...state, mode: Mode.Open };
|
|
26
26
|
case 'CLOSE':
|
|
27
|
-
return { ...state, mode: Mode.Resting };
|
|
27
|
+
return { ...state, mode: Mode.Resting, focused: undefined };
|
|
28
28
|
case 'SELECT':
|
|
29
29
|
return {
|
|
30
30
|
...state,
|
|
@@ -44,6 +44,7 @@ interface UseSelectProps {
|
|
|
44
44
|
|
|
45
45
|
export const useSelect = ({ value, defaultValue }: UseSelectProps) => {
|
|
46
46
|
const selectRef = useRef<HTMLDivElement>(null);
|
|
47
|
+
const buttonRef = useRef<HTMLButtonElement>(null);
|
|
47
48
|
|
|
48
49
|
const initialValue = value ?? defaultValue;
|
|
49
50
|
|
|
@@ -57,7 +58,9 @@ export const useSelect = ({ value, defaultValue }: UseSelectProps) => {
|
|
|
57
58
|
switch (event.key) {
|
|
58
59
|
case 'Escape': {
|
|
59
60
|
event.preventDefault();
|
|
60
|
-
|
|
61
|
+
dispatch({ type: 'CLOSE' });
|
|
62
|
+
buttonRef.current?.focus();
|
|
63
|
+
break;
|
|
61
64
|
}
|
|
62
65
|
default:
|
|
63
66
|
break;
|
|
@@ -81,5 +84,5 @@ export const useSelect = ({ value, defaultValue }: UseSelectProps) => {
|
|
|
81
84
|
dispatch({ type: 'SELECT', payload: { value: value ?? '' } });
|
|
82
85
|
}, [value]);
|
|
83
86
|
|
|
84
|
-
return { state, dispatch, Mode, selectRef };
|
|
87
|
+
return { state, dispatch, Mode, selectRef, buttonRef };
|
|
85
88
|
};
|