@linzjs/lui 21.51.0 → 21.52.0

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/CHANGELOG.md CHANGED
@@ -1,3 +1,17 @@
1
+ # [21.52.0](https://github.com/linz/lui/compare/v21.51.1...v21.52.0) (2024-11-03)
2
+
3
+
4
+ ### Features
5
+
6
+ * Adding onNavigateOutOfBounds callback to LuiListBox ([#1168](https://github.com/linz/lui/issues/1168)) ([1146b6f](https://github.com/linz/lui/commit/1146b6f719be86b206687862ca8043958e44c211))
7
+
8
+ ## [21.51.1](https://github.com/linz/lui/compare/v21.51.0...v21.51.1) (2024-10-31)
9
+
10
+
11
+ ### Bug Fixes
12
+
13
+ * disable prop will now disable all the keys ([#1167](https://github.com/linz/lui/issues/1167)) ([eddfa40](https://github.com/linz/lui/commit/eddfa40b27aa8b914d05da6d1496cbe0b8f50853))
14
+
1
15
  # [21.51.0](https://github.com/linz/lui/compare/v21.50.0...v21.51.0) (2024-10-30)
2
16
 
3
17
 
@@ -44,5 +44,6 @@ export interface ILuiListBoxProps<T = ILuiListBoxItem> extends Omit<HTMLAttribut
44
44
  getLabel?: LabelGetter<T>;
45
45
  loadingIndicator?: () => ReactNode;
46
46
  emptyIndicator?: () => ReactNode;
47
+ onNavigateOutOfBounds?: (bound: 'start' | 'end') => void;
47
48
  }
48
- export declare function LuiListBox<T extends object = ILuiListBoxItem>({ ariaLabel, ariaLabelledBy, itemRenderer, groupHeadingRenderer, loadingIndicator, emptyIndicator, selectionMode, selectionBehavior, disabled, disabledKeys, items, value, onChange, getKey, getGroup, getLabel, ariaProps, className, ...ulProps }: ILuiListBoxProps<T>): JSX.Element;
49
+ export declare function LuiListBox<T extends object = ILuiListBoxItem>({ ariaLabel, ariaLabelledBy, itemRenderer, groupHeadingRenderer, loadingIndicator, emptyIndicator, selectionMode, selectionBehavior, disabled, disabledKeys, items, value, onChange, getKey, getGroup, getLabel, ariaProps, className, onNavigateOutOfBounds, ...ulProps }: ILuiListBoxProps<T>): JSX.Element;
@@ -1,3 +1,3 @@
1
1
  import { ListProps } from '@react-stately/list';
2
2
  import { ILuiListBoxProps, ILuiListItemNode } from './LuiListBox';
3
- export declare function useLuiListBox<T extends object>({ selectionMode, selectionBehavior, items, value, onChange, ariaProps, disabledKeys, getGroup, getKey, getLabel, }: ILuiListBoxProps<T>): ListProps<ILuiListItemNode<T>>;
3
+ export declare function useLuiListBox<T extends object>({ selectionMode, selectionBehavior, items, value, onChange, ariaProps, disabled, disabledKeys, getGroup, getKey, getLabel, }: ILuiListBoxProps<T>): ListProps<ILuiListItemNode<T>>;
package/dist/index.js CHANGED
@@ -55169,7 +55169,7 @@ function $453cc9f0df89c0a5$export$77d5aafae4e095b2(collection) {
55169
55169
  }
55170
55170
 
55171
55171
  function useLuiListBox(_a) {
55172
- var selectionMode = _a.selectionMode, selectionBehavior = _a.selectionBehavior, _b = _a.items, items = _b === void 0 ? [] : _b, value = _a.value, onChange = _a.onChange, ariaProps = _a.ariaProps, disabledKeys = _a.disabledKeys, _c = _a.getGroup, getGroup = _c === void 0 ? defaultGroupGetter : _c, _d = _a.getKey, getKey = _d === void 0 ? defaultKeyGetter : _d, _e = _a.getLabel, getLabel = _e === void 0 ? defaultLabelGetter : _e;
55172
+ var selectionMode = _a.selectionMode, selectionBehavior = _a.selectionBehavior, _b = _a.items, items = _b === void 0 ? [] : _b, value = _a.value, onChange = _a.onChange, ariaProps = _a.ariaProps, _c = _a.disabled, disabled = _c === void 0 ? false : _c, disabledKeys = _a.disabledKeys, _d = _a.getGroup, getGroup = _d === void 0 ? defaultGroupGetter : _d, _e = _a.getKey, getKey = _e === void 0 ? defaultKeyGetter : _e, _f = _a.getLabel, getLabel = _f === void 0 ? defaultLabelGetter : _f;
55173
55173
  var children = React.useCallback(function (item) {
55174
55174
  return item.childNodes ? (React__default["default"].createElement($9fc4852771d079eb$export$6e2c8f0811a474ce, { key: item.key, items: item.childNodes, title: item.textValue }, function (item) { return React__default["default"].createElement($c1d7fb2ec91bae71$export$6d08773d2e66f8f2, null, String(item.key)); })) : (React__default["default"].createElement($c1d7fb2ec91bae71$export$6d08773d2e66f8f2, null, String(item.key)));
55175
55175
  }, []);
@@ -55177,10 +55177,10 @@ function useLuiListBox(_a) {
55177
55177
  if (!onChange) {
55178
55178
  return;
55179
55179
  }
55180
- onChange(keys === 'all' ? items.map(function (item) { return getKey(item); }) : Array.from(keys), keys === 'all' ? items : items.filter(function (item) { return keys.has(getKey(item)); }));
55180
+ onChange(keys === 'all' ? items.map(getKey) : Array.from(keys), keys === 'all' ? items : items.filter(function (item) { return keys.has(getKey(item)); }));
55181
55181
  }, [items, onChange, getKey]);
55182
55182
  var nodes = React.useMemo(function () { return mapItemsToNodes(items, getKey, getGroup, getLabel); }, [items, getKey, getGroup, getLabel]);
55183
- return __assign(__assign({}, ariaProps), { items: nodes, selectionMode: selectionMode, selectionBehavior: selectionBehavior, selectedKeys: (Array.isArray(value) ? value : [value]).filter(Boolean), children: children, onSelectionChange: onSelectionChange, disabledKeys: disabledKeys });
55183
+ return __assign(__assign({}, ariaProps), { items: nodes, selectionMode: selectionMode, selectionBehavior: selectionBehavior, selectedKeys: (Array.isArray(value) ? value : [value]).filter(Boolean), children: children, onSelectionChange: onSelectionChange, disabledKeys: disabled ? items.map(getKey) : disabledKeys });
55184
55184
  }
55185
55185
  function mapItemsToNodes(items, getKey, getGroup, getLabel) {
55186
55186
  var rootNodes = new Map();
@@ -58331,7 +58331,7 @@ function LuiListBoxGroup(_a) {
58331
58331
  }
58332
58332
 
58333
58333
  function LuiListBox(_a) {
58334
- var ariaLabel = _a.ariaLabel, ariaLabelledBy = _a.ariaLabelledBy, _b = _a.itemRenderer, itemRenderer = _b === void 0 ? DefaultItemRenderer : _b, _c = _a.groupHeadingRenderer, groupHeadingRenderer = _c === void 0 ? DefaultGroupHeadingRenderer : _c, _d = _a.loadingIndicator, loadingIndicator = _d === void 0 ? DefaultLoadingIndicator : _d, _e = _a.emptyIndicator, emptyIndicator = _e === void 0 ? DefaultEmptyIndicator : _e, _f = _a.selectionMode, selectionMode = _f === void 0 ? 'single' : _f, _g = _a.selectionBehavior, selectionBehavior = _g === void 0 ? 'toggle' : _g, _h = _a.disabled, disabled = _h === void 0 ? false : _h, _j = _a.disabledKeys, disabledKeys = _j === void 0 ? [] : _j, items = _a.items, value = _a.value, onChange = _a.onChange, getKey = _a.getKey, getGroup = _a.getGroup, getLabel = _a.getLabel, ariaProps = _a.ariaProps, className = _a.className, ulProps = __rest(_a, ["ariaLabel", "ariaLabelledBy", "itemRenderer", "groupHeadingRenderer", "loadingIndicator", "emptyIndicator", "selectionMode", "selectionBehavior", "disabled", "disabledKeys", "items", "value", "onChange", "getKey", "getGroup", "getLabel", "ariaProps", "className"]);
58334
+ var ariaLabel = _a.ariaLabel, ariaLabelledBy = _a.ariaLabelledBy, _b = _a.itemRenderer, itemRenderer = _b === void 0 ? DefaultItemRenderer : _b, _c = _a.groupHeadingRenderer, groupHeadingRenderer = _c === void 0 ? DefaultGroupHeadingRenderer : _c, _d = _a.loadingIndicator, loadingIndicator = _d === void 0 ? DefaultLoadingIndicator : _d, _e = _a.emptyIndicator, emptyIndicator = _e === void 0 ? DefaultEmptyIndicator : _e, _f = _a.selectionMode, selectionMode = _f === void 0 ? 'single' : _f, _g = _a.selectionBehavior, selectionBehavior = _g === void 0 ? 'toggle' : _g, _h = _a.disabled, disabled = _h === void 0 ? false : _h, _j = _a.disabledKeys, disabledKeys = _j === void 0 ? [] : _j, items = _a.items, value = _a.value, onChange = _a.onChange, getKey = _a.getKey, getGroup = _a.getGroup, getLabel = _a.getLabel, ariaProps = _a.ariaProps, className = _a.className, onNavigateOutOfBounds = _a.onNavigateOutOfBounds, ulProps = __rest(_a, ["ariaLabel", "ariaLabelledBy", "itemRenderer", "groupHeadingRenderer", "loadingIndicator", "emptyIndicator", "selectionMode", "selectionBehavior", "disabled", "disabledKeys", "items", "value", "onChange", "getKey", "getGroup", "getLabel", "ariaProps", "className", "onNavigateOutOfBounds"]);
58335
58335
  var listProps = useLuiListBox({
58336
58336
  selectionMode: selectionMode,
58337
58337
  selectionBehavior: selectionBehavior,
@@ -58349,7 +58349,24 @@ function LuiListBox(_a) {
58349
58349
  var ref = React.useRef(null);
58350
58350
  var state = $e72dd72e1c76a225$export$2f645645f7bca764(listProps);
58351
58351
  var listBoxProps = $c132121280ec012d$export$50eacbbf140a3141(ariaListBoxProps, state, ref).listBoxProps;
58352
- return (React__default["default"].createElement("ul", __assign({}, ulProps, listBoxProps, { ref: ref, className: clsx('LuiListBox', className) }),
58352
+ var onKeyDown = function (e) {
58353
+ var _a, _b;
58354
+ var lastFocusedKey = state.selectionManager.focusedKey;
58355
+ (_a = listBoxProps.onKeyDown) === null || _a === void 0 ? void 0 : _a.call(listBoxProps, e);
58356
+ (_b = ulProps.onKeyDown) === null || _b === void 0 ? void 0 : _b.call(ulProps, e);
58357
+ var currentFocusedKey = state.selectionManager.focusedKey;
58358
+ // Events can bubble through portals, ensure we are dealing with an element in this list (not a modal or menu rendered by an item in the list)
58359
+ if (!e.currentTarget.contains(e.target)) {
58360
+ return;
58361
+ }
58362
+ if (e.key === 'ArrowUp' && lastFocusedKey === currentFocusedKey) {
58363
+ onNavigateOutOfBounds === null || onNavigateOutOfBounds === void 0 ? void 0 : onNavigateOutOfBounds('start');
58364
+ }
58365
+ if (e.key === 'ArrowDown' && lastFocusedKey === currentFocusedKey) {
58366
+ onNavigateOutOfBounds === null || onNavigateOutOfBounds === void 0 ? void 0 : onNavigateOutOfBounds('end');
58367
+ }
58368
+ };
58369
+ return (React__default["default"].createElement("ul", __assign({}, ulProps, listBoxProps, { onKeyDown: onKeyDown, ref: ref, className: clsx('LuiListBox', className) }),
58353
58370
  !items && loadingIndicator(),
58354
58371
  (items === null || items === void 0 ? void 0 : items.length) === 0 && emptyIndicator(),
58355
58372
  Array.from(state.collection).map(function (node) {