@basic-ui/core 0.0.45 → 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 +20 -6
- package/build/cjs/index.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/hooks/useControlledState.js +3 -1
- package/build/esm/hooks/useControlledState.js.map +1 -1
- package/build/tsconfig-build.tsbuildinfo +1 -1
- package/package.json +2 -2
- 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/hooks/useControlledState.ts +7 -1
package/build/cjs/index.js
CHANGED
|
@@ -216,11 +216,13 @@ function wrapEvent(theirHandler, ourHandler) {
|
|
|
216
216
|
function useControlledState(valueProp, onChangeProp, defaultValue, defaultOnChange) {
|
|
217
217
|
const isControlled = valueProp !== undefined;
|
|
218
218
|
const wasControlled = react.useRef(isControlled);
|
|
219
|
+
const hasWarned = react.useRef(false);
|
|
219
220
|
const [valueState, setValueState] = react.useState(defaultValue);
|
|
220
221
|
|
|
221
222
|
if (isControlled) {
|
|
222
|
-
if (wasControlled.current && process.env.NODE_ENV !== 'production') {
|
|
223
|
+
if (wasControlled.current && process.env.NODE_ENV !== 'production' && !hasWarned.current) {
|
|
223
224
|
console.warn('Trying to change from controlled to uncontrolled.');
|
|
225
|
+
hasWarned.current = true;
|
|
224
226
|
}
|
|
225
227
|
|
|
226
228
|
return [// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
@@ -2035,7 +2037,6 @@ const MenuItem = /*#__PURE__*/react.forwardRef(function MenuItem(props, forwarde
|
|
|
2035
2037
|
const handleKeyDown = e => {
|
|
2036
2038
|
switch (e.key) {
|
|
2037
2039
|
case 'Enter':
|
|
2038
|
-
case ' ':
|
|
2039
2040
|
if (!disabled) {
|
|
2040
2041
|
handleSelect(e);
|
|
2041
2042
|
}
|
|
@@ -2073,6 +2074,8 @@ const MenuList = /*#__PURE__*/react.forwardRef(function MenuList(props, forwarde
|
|
|
2073
2074
|
defaultActiveItemValue,
|
|
2074
2075
|
...otherProps
|
|
2075
2076
|
} = props;
|
|
2077
|
+
const itemSearchStr = react.useRef('');
|
|
2078
|
+
const itemSearchClearTimeout = react.useRef();
|
|
2076
2079
|
const {
|
|
2077
2080
|
menuListIdRef,
|
|
2078
2081
|
buttonRef,
|
|
@@ -2129,6 +2132,7 @@ const MenuList = /*#__PURE__*/react.forwardRef(function MenuList(props, forwarde
|
|
|
2129
2132
|
onChange && onChange(e, false);
|
|
2130
2133
|
e.preventDefault(); // prevents focusing on next element, because we will be handling it
|
|
2131
2134
|
|
|
2135
|
+
itemSearchStr.current = '';
|
|
2132
2136
|
buttonRef.current?.focus();
|
|
2133
2137
|
break;
|
|
2134
2138
|
}
|
|
@@ -2138,6 +2142,7 @@ const MenuList = /*#__PURE__*/react.forwardRef(function MenuList(props, forwarde
|
|
|
2138
2142
|
case 'ArrowDown':
|
|
2139
2143
|
case 'ArrowUp':
|
|
2140
2144
|
e.preventDefault();
|
|
2145
|
+
itemSearchStr.current = '';
|
|
2141
2146
|
const allItems = scope ? scope.current.queryAllNodes(queryScope) : [];
|
|
2142
2147
|
const currentIndex = allItems.findIndex(e => e === navigationItem);
|
|
2143
2148
|
|
|
@@ -2173,21 +2178,30 @@ const MenuList = /*#__PURE__*/react.forwardRef(function MenuList(props, forwarde
|
|
|
2173
2178
|
|
|
2174
2179
|
default:
|
|
2175
2180
|
{
|
|
2176
|
-
if (e.key.length === 1) {
|
|
2181
|
+
if (e.key.length === 1 && !e.ctrlKey && !e.altKey) {
|
|
2177
2182
|
// A-Z
|
|
2178
2183
|
e.preventDefault();
|
|
2184
|
+
|
|
2185
|
+
if (itemSearchStr.current.length === 0 || itemSearchStr.current.slice(-1) !== e.key) {
|
|
2186
|
+
itemSearchStr.current = itemSearchStr.current + e.key;
|
|
2187
|
+
}
|
|
2188
|
+
|
|
2189
|
+
clearTimeout(itemSearchClearTimeout.current);
|
|
2190
|
+
itemSearchClearTimeout.current = setTimeout(() => {
|
|
2191
|
+
itemSearchStr.current = '';
|
|
2192
|
+
}, 500);
|
|
2179
2193
|
const allItems = scope ? scope.current.queryAllNodes(queryScope) : [];
|
|
2180
2194
|
const currentIndex = allItems.findIndex(e => e === navigationItem);
|
|
2181
|
-
const
|
|
2195
|
+
const searchStr = itemSearchStr.current;
|
|
2182
2196
|
let nextIndex = -1;
|
|
2183
2197
|
|
|
2184
|
-
for (let i = 1; i < allItems.length; i++) {
|
|
2198
|
+
for (let i = searchStr.length === 1 ? 1 : 0; i < allItems.length; i++) {
|
|
2185
2199
|
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
2186
2200
|
const idx = getCircularIndex(currentIndex + i, allItems.length);
|
|
2187
2201
|
const dom = allItems[idx];
|
|
2188
2202
|
const domText = dom.innerText.toLowerCase();
|
|
2189
2203
|
|
|
2190
|
-
if (domText.length > 0 && domText.
|
|
2204
|
+
if (domText.length > 0 && domText.startsWith(searchStr)) {
|
|
2191
2205
|
nextIndex = idx;
|
|
2192
2206
|
break;
|
|
2193
2207
|
}
|