@basic-ui/core 0.0.43 → 0.0.46
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/build/cjs/index.js +92 -47
- package/build/cjs/index.js.map +1 -1
- package/build/esm/ComboBox/hooks.js +51 -15
- package/build/esm/ComboBox/hooks.js.map +1 -1
- package/build/esm/Menu/MenuItem.js +0 -1
- package/build/esm/Menu/MenuItem.js.map +1 -1
- package/build/esm/Menu/MenuList.js +18 -4
- package/build/esm/Menu/MenuList.js.map +1 -1
- package/build/esm/Menu/fixtures/countryList.d.ts +1 -0
- package/build/esm/Menu/fixtures/countryList.js +2 -0
- package/build/esm/Menu/fixtures/countryList.js.map +1 -0
- package/build/esm/Slider/Slider.d.ts +0 -21
- package/build/esm/Slider/Slider.js +27 -10
- package/build/esm/Slider/Slider.js.map +1 -1
- package/build/esm/hooks/useControlledState.js +3 -1
- package/build/esm/hooks/useControlledState.js.map +1 -1
- package/build/esm/utils/polymorphic.d.ts +7 -0
- package/build/esm/utils/polymorphic.js.map +1 -1
- package/build/tsconfig-build.tsbuildinfo +1 -1
- package/package.json +2 -2
- package/src/ComboBox/ComboBox.story.tsx +1 -1
- package/src/ComboBox/hooks.tsx +40 -15
- package/src/ComboBox/styles.css +2 -0
- package/src/Menu/MenuComplex.story.tsx +58 -0
- package/src/Menu/MenuItem.tsx +0 -1
- package/src/Menu/MenuList.tsx +25 -4
- package/src/Menu/fixtures/countryList.ts +198 -0
- package/src/Slider/Slider.tsx +18 -4
- package/src/hooks/useControlledState.ts +7 -1
- package/src/utils/polymorphic.ts +13 -7
package/src/Menu/MenuList.tsx
CHANGED
|
@@ -33,6 +33,9 @@ export const MenuList = forwardRef<HTMLUListElement, MenuListProps>(
|
|
|
33
33
|
...otherProps
|
|
34
34
|
} = props;
|
|
35
35
|
|
|
36
|
+
const itemSearchStr = useRef('');
|
|
37
|
+
const itemSearchClearTimeout = useRef<ReturnType<typeof setTimeout>>();
|
|
38
|
+
|
|
36
39
|
const { menuListIdRef, buttonRef, onChange, openWithArrowKeyRef, open } =
|
|
37
40
|
useMenuContext();
|
|
38
41
|
|
|
@@ -107,6 +110,7 @@ export const MenuList = forwardRef<HTMLUListElement, MenuListProps>(
|
|
|
107
110
|
case 'Tab': {
|
|
108
111
|
onChange && onChange(e, false);
|
|
109
112
|
e.preventDefault(); // prevents focusing on next element, because we will be handling it
|
|
113
|
+
itemSearchStr.current = '';
|
|
110
114
|
buttonRef.current?.focus();
|
|
111
115
|
break;
|
|
112
116
|
}
|
|
@@ -115,6 +119,7 @@ export const MenuList = forwardRef<HTMLUListElement, MenuListProps>(
|
|
|
115
119
|
case 'ArrowDown':
|
|
116
120
|
case 'ArrowUp':
|
|
117
121
|
e.preventDefault();
|
|
122
|
+
itemSearchStr.current = '';
|
|
118
123
|
const allItems = scope ? scope.current.queryAllNodes(queryScope) : [];
|
|
119
124
|
const currentIndex = allItems.findIndex((e) => e === navigationItem);
|
|
120
125
|
if (allItems.length === 0) {
|
|
@@ -141,23 +146,39 @@ export const MenuList = forwardRef<HTMLUListElement, MenuListProps>(
|
|
|
141
146
|
onNavigate && onNavigate(allItems[nextIndex]);
|
|
142
147
|
break;
|
|
143
148
|
default: {
|
|
144
|
-
if (e.key.length === 1) {
|
|
149
|
+
if (e.key.length === 1 && !e.ctrlKey && !e.altKey) {
|
|
145
150
|
// A-Z
|
|
146
151
|
e.preventDefault();
|
|
152
|
+
|
|
153
|
+
if (
|
|
154
|
+
itemSearchStr.current.length === 0 ||
|
|
155
|
+
itemSearchStr.current.slice(-1) !== e.key
|
|
156
|
+
) {
|
|
157
|
+
itemSearchStr.current = itemSearchStr.current + e.key;
|
|
158
|
+
}
|
|
159
|
+
clearTimeout(itemSearchClearTimeout.current as any);
|
|
160
|
+
itemSearchClearTimeout.current = setTimeout(() => {
|
|
161
|
+
itemSearchStr.current = '';
|
|
162
|
+
}, 500);
|
|
163
|
+
|
|
147
164
|
const allItems = scope
|
|
148
165
|
? scope.current.queryAllNodes(queryScope)
|
|
149
166
|
: [];
|
|
150
167
|
const currentIndex = allItems.findIndex(
|
|
151
168
|
(e) => e === navigationItem
|
|
152
169
|
);
|
|
153
|
-
const
|
|
170
|
+
const searchStr = itemSearchStr.current;
|
|
154
171
|
let nextIndex = -1;
|
|
155
|
-
for (
|
|
172
|
+
for (
|
|
173
|
+
let i = searchStr.length === 1 ? 1 : 0;
|
|
174
|
+
i < allItems.length;
|
|
175
|
+
i++
|
|
176
|
+
) {
|
|
156
177
|
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
157
178
|
const idx = getCircularIndex(currentIndex + i, allItems.length)!;
|
|
158
179
|
const dom = allItems[idx];
|
|
159
180
|
const domText = dom.innerText.toLowerCase();
|
|
160
|
-
if (domText.length > 0 && domText.
|
|
181
|
+
if (domText.length > 0 && domText.startsWith(searchStr)) {
|
|
161
182
|
nextIndex = idx;
|
|
162
183
|
break;
|
|
163
184
|
}
|
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
export const countryList = [
|
|
2
|
+
'Afghanistan',
|
|
3
|
+
'Albania',
|
|
4
|
+
'Algeria',
|
|
5
|
+
'Andorra',
|
|
6
|
+
'Angola',
|
|
7
|
+
'Antigua and Barbuda',
|
|
8
|
+
'Argentina',
|
|
9
|
+
'Armenia',
|
|
10
|
+
'Australia',
|
|
11
|
+
'Austria',
|
|
12
|
+
'Azerbaijan',
|
|
13
|
+
'Bahamas',
|
|
14
|
+
'Bahrain',
|
|
15
|
+
'Bangladesh',
|
|
16
|
+
'Barbados',
|
|
17
|
+
'Belarus',
|
|
18
|
+
'Belgium',
|
|
19
|
+
'Belize',
|
|
20
|
+
'Benin',
|
|
21
|
+
'Bhutan',
|
|
22
|
+
'Bolivia',
|
|
23
|
+
'Bosnia and Herzegovina',
|
|
24
|
+
'Botswana',
|
|
25
|
+
'Brazil',
|
|
26
|
+
'Brunei',
|
|
27
|
+
'Bulgaria',
|
|
28
|
+
'Burkina Faso',
|
|
29
|
+
'Burundi',
|
|
30
|
+
"Côte d'Ivoire",
|
|
31
|
+
'Cabo Verde',
|
|
32
|
+
'Cambodia',
|
|
33
|
+
'Cameroon',
|
|
34
|
+
'Canada',
|
|
35
|
+
'Central African Republic',
|
|
36
|
+
'Central American Republic',
|
|
37
|
+
'Chad',
|
|
38
|
+
'Chile',
|
|
39
|
+
'China',
|
|
40
|
+
'Colombia',
|
|
41
|
+
'Comoros',
|
|
42
|
+
'Congo (Congo-Brazzaville)',
|
|
43
|
+
'Costa Rica',
|
|
44
|
+
'Croatia',
|
|
45
|
+
'Cuba',
|
|
46
|
+
'Cyprus',
|
|
47
|
+
'Czechia (Czech Republic)',
|
|
48
|
+
'Democratic Republic of the Congo',
|
|
49
|
+
'Denmark',
|
|
50
|
+
'Djibouti',
|
|
51
|
+
'Dominica',
|
|
52
|
+
'Dominican Republic',
|
|
53
|
+
'Ecuador',
|
|
54
|
+
'Egypt',
|
|
55
|
+
'El Salvador',
|
|
56
|
+
'Equatorial Guinea',
|
|
57
|
+
'Eritrea',
|
|
58
|
+
'Estonia',
|
|
59
|
+
'Eswatini (fmr. "Swaziland")',
|
|
60
|
+
'Ethiopia',
|
|
61
|
+
'Fiji',
|
|
62
|
+
'Finland',
|
|
63
|
+
'France',
|
|
64
|
+
'Gabon',
|
|
65
|
+
'Gambia',
|
|
66
|
+
'Georgia',
|
|
67
|
+
'Germany',
|
|
68
|
+
'Ghana',
|
|
69
|
+
'Greece',
|
|
70
|
+
'Grenada',
|
|
71
|
+
'Guatemala',
|
|
72
|
+
'Guinea',
|
|
73
|
+
'Guinea-Bissau',
|
|
74
|
+
'Guyana',
|
|
75
|
+
'Haiti',
|
|
76
|
+
'Holy See',
|
|
77
|
+
'Honduras',
|
|
78
|
+
'Hungary',
|
|
79
|
+
'Iceland',
|
|
80
|
+
'India',
|
|
81
|
+
'Indonesia',
|
|
82
|
+
'Iran',
|
|
83
|
+
'Iraq',
|
|
84
|
+
'Ireland',
|
|
85
|
+
'Israel',
|
|
86
|
+
'Italy',
|
|
87
|
+
'Jamaica',
|
|
88
|
+
'Japan',
|
|
89
|
+
'Jordan',
|
|
90
|
+
'Kazakhstan',
|
|
91
|
+
'Kenya',
|
|
92
|
+
'Kiribati',
|
|
93
|
+
'Kuwait',
|
|
94
|
+
'Kyrgyzstan',
|
|
95
|
+
'Laos',
|
|
96
|
+
'Latvia',
|
|
97
|
+
'Lebanon',
|
|
98
|
+
'Lesotho',
|
|
99
|
+
'Liberia',
|
|
100
|
+
'Libya',
|
|
101
|
+
'Liechtenstein',
|
|
102
|
+
'Lithuania',
|
|
103
|
+
'Luxembourg',
|
|
104
|
+
'Madagascar',
|
|
105
|
+
'Malawi',
|
|
106
|
+
'Malaysia',
|
|
107
|
+
'Maldives',
|
|
108
|
+
'Mali',
|
|
109
|
+
'Malta',
|
|
110
|
+
'Marshall Islands',
|
|
111
|
+
'Mauritania',
|
|
112
|
+
'Mauritius',
|
|
113
|
+
'Mexico',
|
|
114
|
+
'Micronesia',
|
|
115
|
+
'Moldova',
|
|
116
|
+
'Monaco',
|
|
117
|
+
'Mongolia',
|
|
118
|
+
'Montenegro',
|
|
119
|
+
'Morocco',
|
|
120
|
+
'Mozambique',
|
|
121
|
+
'Myanmar (formerly Burma)',
|
|
122
|
+
'Namibia',
|
|
123
|
+
'Nauru',
|
|
124
|
+
'Nepal',
|
|
125
|
+
'Netherlands',
|
|
126
|
+
'New Zealand',
|
|
127
|
+
'Nicaragua',
|
|
128
|
+
'Niger',
|
|
129
|
+
'Nigeria',
|
|
130
|
+
'North Korea',
|
|
131
|
+
'North Macedonia',
|
|
132
|
+
'Norway',
|
|
133
|
+
'Oman',
|
|
134
|
+
'Pakistan',
|
|
135
|
+
'Palau',
|
|
136
|
+
'Palestine State',
|
|
137
|
+
'Panama',
|
|
138
|
+
'Papua New Guinea',
|
|
139
|
+
'Paraguay',
|
|
140
|
+
'Peru',
|
|
141
|
+
'Philippines',
|
|
142
|
+
'Poland',
|
|
143
|
+
'Portugal',
|
|
144
|
+
'Qatar',
|
|
145
|
+
'Romania',
|
|
146
|
+
'Russia',
|
|
147
|
+
'Rwanda',
|
|
148
|
+
'Saint Kitts and Nevis',
|
|
149
|
+
'Saint Lucia',
|
|
150
|
+
'Saint Vincent and the Grenadines',
|
|
151
|
+
'Samoa',
|
|
152
|
+
'San Marino',
|
|
153
|
+
'Sao Tome and Principe',
|
|
154
|
+
'Saudi Arabia',
|
|
155
|
+
'Senegal',
|
|
156
|
+
'Serbia',
|
|
157
|
+
'Seychelles',
|
|
158
|
+
'Sierra Leone',
|
|
159
|
+
'Singapore',
|
|
160
|
+
'Slovakia',
|
|
161
|
+
'Slovenia',
|
|
162
|
+
'Solomon Islands',
|
|
163
|
+
'Somalia',
|
|
164
|
+
'South Africa',
|
|
165
|
+
'South Korea',
|
|
166
|
+
'South Sudan',
|
|
167
|
+
'Spain',
|
|
168
|
+
'Sri Lanka',
|
|
169
|
+
'Sudan',
|
|
170
|
+
'Suriname',
|
|
171
|
+
'Sweden',
|
|
172
|
+
'Switzerland',
|
|
173
|
+
'Syria',
|
|
174
|
+
'Tajikistan',
|
|
175
|
+
'Tanzania',
|
|
176
|
+
'Thailand',
|
|
177
|
+
'Timor-Leste',
|
|
178
|
+
'Togo',
|
|
179
|
+
'Tonga',
|
|
180
|
+
'Trinidad and Tobago',
|
|
181
|
+
'Tunisia',
|
|
182
|
+
'Turkey',
|
|
183
|
+
'Turkmenistan',
|
|
184
|
+
'Tuvalu',
|
|
185
|
+
'Uganda',
|
|
186
|
+
'Ukraine',
|
|
187
|
+
'United Arab Emirates',
|
|
188
|
+
'United Kingdom',
|
|
189
|
+
'United States of America',
|
|
190
|
+
'Uruguay',
|
|
191
|
+
'Uzbekistan',
|
|
192
|
+
'Vanuatu',
|
|
193
|
+
'Venezuela',
|
|
194
|
+
'Vietnam',
|
|
195
|
+
'Yemen',
|
|
196
|
+
'Zambia',
|
|
197
|
+
'Zimbabwe',
|
|
198
|
+
];
|
package/src/Slider/Slider.tsx
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
/* eslint-disable @typescript-eslint/ban-ts-comment */
|
|
2
|
+
|
|
1
3
|
/**
|
|
2
4
|
* Welcome to @reach/slider!
|
|
3
5
|
*
|
|
@@ -204,6 +206,7 @@ const SliderInput = forwardRef(function SliderInput(
|
|
|
204
206
|
'aria-labelledby': ariaLabelledBy,
|
|
205
207
|
'aria-valuetext': ariaValueTextProp,
|
|
206
208
|
as: Comp = 'div',
|
|
209
|
+
innerAs,
|
|
207
210
|
defaultValue,
|
|
208
211
|
disabled = false,
|
|
209
212
|
value: controlledValue,
|
|
@@ -594,6 +597,8 @@ const SliderInput = forwardRef(function SliderInput(
|
|
|
594
597
|
>
|
|
595
598
|
<Comp
|
|
596
599
|
{...rest}
|
|
600
|
+
// @ts-ignore
|
|
601
|
+
as={innerAs}
|
|
597
602
|
ref={assignMultipleRefs(sliderRef, forwardedRef)}
|
|
598
603
|
data-reach-slider-input=""
|
|
599
604
|
data-disabled={disabled ? '' : undefined}
|
|
@@ -645,7 +650,7 @@ type SliderInputProps = Omit<SliderProps, 'children'> & {
|
|
|
645
650
|
* @see Docs https://reach.tech/slider#slidertrack
|
|
646
651
|
*/
|
|
647
652
|
const SliderTrackImpl = forwardRef(function SliderTrack(
|
|
648
|
-
{ as: Comp = 'div', children, style = {}, ...props },
|
|
653
|
+
{ as: Comp = 'div', innerAs, children, style = {}, ...props },
|
|
649
654
|
forwardedRef
|
|
650
655
|
) {
|
|
651
656
|
const { disabled, orientation, trackRef } = useSliderContext('SliderTrack');
|
|
@@ -653,6 +658,8 @@ const SliderTrackImpl = forwardRef(function SliderTrack(
|
|
|
653
658
|
return (
|
|
654
659
|
<Comp
|
|
655
660
|
ref={assignMultipleRefs(trackRef, forwardedRef)}
|
|
661
|
+
// @ts-ignore
|
|
662
|
+
as={innerAs}
|
|
656
663
|
style={{ ...style, position: 'relative' }}
|
|
657
664
|
{...props}
|
|
658
665
|
data-reach-slider-track=""
|
|
@@ -694,13 +701,15 @@ interface SliderTrackProps {
|
|
|
694
701
|
* @see Docs https://reach.tech/slider#sliderrange
|
|
695
702
|
*/
|
|
696
703
|
const SliderRangeImpl = forwardRef(function SliderRange(
|
|
697
|
-
{ as: Comp = 'div', children, style = {}, ...props },
|
|
704
|
+
{ as: Comp = 'div', innerAs, children, style = {}, ...props },
|
|
698
705
|
forwardedRef
|
|
699
706
|
) {
|
|
700
707
|
const { disabled, orientation, rangeStyle } = useSliderContext('SliderRange');
|
|
701
708
|
return (
|
|
702
709
|
<Comp
|
|
703
710
|
ref={forwardedRef}
|
|
711
|
+
// @ts-ignore
|
|
712
|
+
as={innerAs}
|
|
704
713
|
style={{ position: 'absolute', ...rangeStyle, ...style }}
|
|
705
714
|
{...props}
|
|
706
715
|
data-reach-slider-range=""
|
|
@@ -738,6 +747,7 @@ const SliderHandleImpl = forwardRef(function SliderHandle(
|
|
|
738
747
|
// min,
|
|
739
748
|
// max,
|
|
740
749
|
as: Comp = 'div',
|
|
750
|
+
innerAs,
|
|
741
751
|
onBlur,
|
|
742
752
|
onFocus,
|
|
743
753
|
style = {},
|
|
@@ -764,6 +774,8 @@ const SliderHandleImpl = forwardRef(function SliderHandle(
|
|
|
764
774
|
|
|
765
775
|
return (
|
|
766
776
|
<Comp
|
|
777
|
+
// @ts-ignore
|
|
778
|
+
as={innerAs}
|
|
767
779
|
aria-disabled={disabled || undefined}
|
|
768
780
|
// If the slider has a visible label, it is referenced by
|
|
769
781
|
// `aria-labelledby` on the slider element. Otherwise, the slider
|
|
@@ -842,7 +854,7 @@ interface SliderHandleProps {}
|
|
|
842
854
|
* @see Docs https://reach.tech/slider#slidermarker
|
|
843
855
|
*/
|
|
844
856
|
const SliderMarkerImpl = forwardRef(function SliderMarker(
|
|
845
|
-
{ as: Comp = 'div', children, style = {}, value, ...props },
|
|
857
|
+
{ as: Comp = 'div', innerAs, children, style = {}, value, ...props },
|
|
846
858
|
forwardedRef
|
|
847
859
|
) {
|
|
848
860
|
const {
|
|
@@ -854,7 +866,7 @@ const SliderMarkerImpl = forwardRef(function SliderMarker(
|
|
|
854
866
|
value: sliderValue,
|
|
855
867
|
} = useSliderContext('SliderMarker');
|
|
856
868
|
|
|
857
|
-
const inRange =
|
|
869
|
+
const inRange = value >= sliderMin && value <= sliderMax;
|
|
858
870
|
const absoluteStartPosition = `${valueToPercent(
|
|
859
871
|
value,
|
|
860
872
|
sliderMin,
|
|
@@ -871,6 +883,8 @@ const SliderMarkerImpl = forwardRef(function SliderMarker(
|
|
|
871
883
|
return inRange ? (
|
|
872
884
|
<Comp
|
|
873
885
|
ref={forwardedRef}
|
|
886
|
+
// @ts-ignore
|
|
887
|
+
as={innerAs}
|
|
874
888
|
style={{
|
|
875
889
|
position: 'absolute',
|
|
876
890
|
...(isVertical
|
|
@@ -18,11 +18,17 @@ export function useControlledState<
|
|
|
18
18
|
): [V, CustomEventHandler<E, H>] {
|
|
19
19
|
const isControlled = valueProp !== undefined;
|
|
20
20
|
const wasControlled = useRef(isControlled);
|
|
21
|
+
const hasWarned = useRef(false);
|
|
21
22
|
const [valueState, setValueState] = useState<V>(defaultValue);
|
|
22
23
|
|
|
23
24
|
if (isControlled) {
|
|
24
|
-
if (
|
|
25
|
+
if (
|
|
26
|
+
wasControlled.current &&
|
|
27
|
+
process.env.NODE_ENV !== 'production' &&
|
|
28
|
+
!hasWarned.current
|
|
29
|
+
) {
|
|
25
30
|
console.warn('Trying to change from controlled to uncontrolled.');
|
|
31
|
+
hasWarned.current = true;
|
|
26
32
|
}
|
|
27
33
|
return [
|
|
28
34
|
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
package/src/utils/polymorphic.ts
CHANGED
|
@@ -25,7 +25,7 @@ export type IntrinsicElement<E> = E extends ForwardRefComponent<infer I, any>
|
|
|
25
25
|
type ForwardRefExoticComponent<E, OwnProps> = React.ForwardRefExoticComponent<
|
|
26
26
|
Merge<
|
|
27
27
|
E extends React.ElementType ? React.ComponentPropsWithRef<E> : never,
|
|
28
|
-
OwnProps & { as?: E }
|
|
28
|
+
OwnProps & { as?: E; innerAs?: E }
|
|
29
29
|
>
|
|
30
30
|
>;
|
|
31
31
|
|
|
@@ -47,11 +47,14 @@ export interface ForwardRefComponent<
|
|
|
47
47
|
*/
|
|
48
48
|
<As = IntrinsicElementString>(
|
|
49
49
|
props: As extends ''
|
|
50
|
-
? {
|
|
50
|
+
? {
|
|
51
|
+
as: keyof JSX.IntrinsicElements;
|
|
52
|
+
innerAs?: keyof JSX.IntrinsicElements;
|
|
53
|
+
}
|
|
51
54
|
: As extends React.ComponentType<infer P>
|
|
52
|
-
? Merge<P, OwnProps & { as: As }>
|
|
55
|
+
? Merge<P, OwnProps & { as: As; innerAs?: As }>
|
|
53
56
|
: As extends keyof JSX.IntrinsicElements
|
|
54
|
-
? Merge<JSX.IntrinsicElements[As], OwnProps & { as: As }>
|
|
57
|
+
? Merge<JSX.IntrinsicElements[As], OwnProps & { as: As; innerAs?: As }>
|
|
55
58
|
: never
|
|
56
59
|
): React.ReactElement | null;
|
|
57
60
|
}
|
|
@@ -62,11 +65,14 @@ export interface MemoComponent<IntrinsicElementString, OwnProps = {}>
|
|
|
62
65
|
> {
|
|
63
66
|
<As = IntrinsicElementString>(
|
|
64
67
|
props: As extends ''
|
|
65
|
-
? {
|
|
68
|
+
? {
|
|
69
|
+
as: keyof JSX.IntrinsicElements;
|
|
70
|
+
innerAs?: keyof JSX.IntrinsicElements;
|
|
71
|
+
}
|
|
66
72
|
: As extends React.ComponentType<infer P>
|
|
67
|
-
? Merge<P, OwnProps & { as: As }>
|
|
73
|
+
? Merge<P, OwnProps & { as: As; innerAs?: As }>
|
|
68
74
|
: As extends keyof JSX.IntrinsicElements
|
|
69
|
-
? Merge<JSX.IntrinsicElements[As], OwnProps & { as: As }>
|
|
75
|
+
? Merge<JSX.IntrinsicElements[As], OwnProps & { as: As; innerAs?: As }>
|
|
70
76
|
: never
|
|
71
77
|
): React.ReactElement | null;
|
|
72
78
|
}
|