@react-spectrum/listbox 3.13.3 → 3.14.1

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.
Files changed (44) hide show
  1. package/dist/ListBox.main.js +2 -7
  2. package/dist/ListBox.main.js.map +1 -1
  3. package/dist/ListBox.mjs +2 -7
  4. package/dist/ListBox.module.js +2 -7
  5. package/dist/ListBox.module.js.map +1 -1
  6. package/dist/ListBoxBase.main.js +10 -10
  7. package/dist/ListBoxBase.main.js.map +1 -1
  8. package/dist/ListBoxBase.mjs +11 -11
  9. package/dist/ListBoxBase.module.js +11 -11
  10. package/dist/ListBoxBase.module.js.map +1 -1
  11. package/dist/ListBoxContext.main.js.map +1 -1
  12. package/dist/ListBoxContext.module.js.map +1 -1
  13. package/dist/ListBoxLayout.main.js +2 -2
  14. package/dist/ListBoxLayout.main.js.map +1 -1
  15. package/dist/ListBoxLayout.mjs +2 -2
  16. package/dist/ListBoxLayout.module.js +2 -2
  17. package/dist/ListBoxLayout.module.js.map +1 -1
  18. package/dist/ListBoxOption.main.js +1 -1
  19. package/dist/ListBoxOption.main.js.map +1 -1
  20. package/dist/ListBoxOption.mjs +1 -1
  21. package/dist/ListBoxOption.module.js +1 -1
  22. package/dist/ListBoxOption.module.js.map +1 -1
  23. package/dist/ListBoxSection.main.js +2 -2
  24. package/dist/ListBoxSection.main.js.map +1 -1
  25. package/dist/ListBoxSection.mjs +2 -2
  26. package/dist/ListBoxSection.module.js +2 -2
  27. package/dist/ListBoxSection.module.js.map +1 -1
  28. package/dist/menu_vars_css.main.js +55 -55
  29. package/dist/menu_vars_css.main.js.map +1 -1
  30. package/dist/menu_vars_css.mjs +55 -55
  31. package/dist/menu_vars_css.module.js +55 -55
  32. package/dist/menu_vars_css.module.js.map +1 -1
  33. package/dist/types.d.ts +1 -0
  34. package/dist/types.d.ts.map +1 -1
  35. package/dist/{vars.487ba452.css → vars.e5f333b9.css} +117 -116
  36. package/dist/vars.e5f333b9.css.map +1 -0
  37. package/package.json +21 -21
  38. package/src/ListBox.tsx +9 -12
  39. package/src/ListBoxBase.tsx +21 -21
  40. package/src/ListBoxContext.ts +1 -1
  41. package/src/ListBoxLayout.ts +4 -3
  42. package/src/ListBoxOption.tsx +1 -1
  43. package/src/ListBoxSection.tsx +5 -4
  44. package/dist/vars.487ba452.css.map +0 -1
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@react-spectrum/listbox",
3
- "version": "3.13.3",
3
+ "version": "3.14.1",
4
4
  "description": "Spectrum UI components in React",
5
5
  "license": "Apache-2.0",
6
6
  "main": "dist/main.js",
@@ -36,23 +36,23 @@
36
36
  "url": "https://github.com/adobe/react-spectrum"
37
37
  },
38
38
  "dependencies": {
39
- "@react-aria/focus": "^3.18.4",
40
- "@react-aria/i18n": "^3.12.3",
41
- "@react-aria/interactions": "^3.22.4",
42
- "@react-aria/listbox": "^3.13.5",
43
- "@react-aria/utils": "^3.25.3",
44
- "@react-aria/virtualizer": "^4.0.4",
45
- "@react-spectrum/layout": "^3.6.9",
46
- "@react-spectrum/progress": "^3.7.10",
47
- "@react-spectrum/text": "^3.5.9",
48
- "@react-spectrum/utils": "^3.11.11",
49
- "@react-stately/collections": "^3.11.0",
50
- "@react-stately/layout": "^4.0.3",
51
- "@react-stately/list": "^3.11.0",
52
- "@react-stately/virtualizer": "^4.1.0",
53
- "@react-types/listbox": "^3.5.2",
54
- "@react-types/shared": "^3.25.0",
55
- "@spectrum-icons/ui": "^3.6.10",
39
+ "@react-aria/focus": "^3.19.1",
40
+ "@react-aria/i18n": "^3.12.5",
41
+ "@react-aria/interactions": "^3.23.0",
42
+ "@react-aria/listbox": "^3.14.0",
43
+ "@react-aria/utils": "^3.27.0",
44
+ "@react-aria/virtualizer": "^4.1.1",
45
+ "@react-spectrum/layout": "^3.6.11",
46
+ "@react-spectrum/progress": "^3.7.12",
47
+ "@react-spectrum/text": "^3.5.11",
48
+ "@react-spectrum/utils": "^3.12.1",
49
+ "@react-stately/collections": "^3.12.1",
50
+ "@react-stately/layout": "^4.1.1",
51
+ "@react-stately/list": "^3.11.2",
52
+ "@react-stately/virtualizer": "^4.2.1",
53
+ "@react-types/listbox": "^3.5.4",
54
+ "@react-types/shared": "^3.27.0",
55
+ "@spectrum-icons/ui": "^3.6.12",
56
56
  "@swc/helpers": "^0.5.0"
57
57
  },
58
58
  "devDependencies": {
@@ -60,11 +60,11 @@
60
60
  },
61
61
  "peerDependencies": {
62
62
  "@react-spectrum/provider": "^3.2.0",
63
- "react": "^16.8.0 || ^17.0.0-rc.1 || ^18.0.0 || ^19.0.0",
64
- "react-dom": "^16.8.0 || ^17.0.0-rc.1 || ^18.0.0 || ^19.0.0"
63
+ "react": "^16.8.0 || ^17.0.0-rc.1 || ^18.0.0 || ^19.0.0-rc.1",
64
+ "react-dom": "^16.8.0 || ^17.0.0-rc.1 || ^18.0.0 || ^19.0.0-rc.1"
65
65
  },
66
66
  "publishConfig": {
67
67
  "access": "public"
68
68
  },
69
- "gitHead": "8e0a28d188cdbdbd2b32296fa034b1b02ddde229"
69
+ "gitHead": "09e7f44bebdc9d89122926b2b439a0a38a2814ea"
70
70
  }
package/src/ListBox.tsx CHANGED
@@ -17,7 +17,14 @@ import {SpectrumListBoxProps} from '@react-types/listbox';
17
17
  import {useDOMRef} from '@react-spectrum/utils';
18
18
  import {useListState} from '@react-stately/list';
19
19
 
20
- function ListBox<T extends object>(props: SpectrumListBoxProps<T>, ref: DOMRef<HTMLDivElement>) {
20
+ // forwardRef doesn't support generic parameters, so cast the result to the correct type
21
+ // https://stackoverflow.com/questions/58469229/react-with-typescript-generics-while-using-react-forwardref
22
+
23
+
24
+ /**
25
+ * A list of options that can allow selection of one or more.
26
+ */
27
+ export const ListBox = React.forwardRef(function ListBox<T extends object>(props: SpectrumListBoxProps<T>, ref: DOMRef<HTMLDivElement>) {
21
28
  let state = useListState(props);
22
29
  let layout = useListBoxLayout();
23
30
  let domRef = useDOMRef(ref);
@@ -29,14 +36,4 @@ function ListBox<T extends object>(props: SpectrumListBoxProps<T>, ref: DOMRef<H
29
36
  state={state}
30
37
  layout={layout} />
31
38
  );
32
- }
33
-
34
- // forwardRef doesn't support generic parameters, so cast the result to the correct type
35
- // https://stackoverflow.com/questions/58469229/react-with-typescript-generics-while-using-react-forwardref
36
-
37
-
38
- /**
39
- * A list of options that can allow selection of one or more.
40
- */
41
- const _ListBox = React.forwardRef(ListBox) as <T>(props: SpectrumListBoxProps<T> & {ref?: DOMRef<HTMLDivElement>}) => ReactElement;
42
- export {_ListBox as ListBox};
39
+ }) as <T>(props: SpectrumListBoxProps<T> & {ref?: DOMRef<HTMLDivElement>}) => ReactElement;
@@ -21,9 +21,9 @@ import {ListBoxLayout} from './ListBoxLayout';
21
21
  import {ListBoxOption} from './ListBoxOption';
22
22
  import {ListBoxSection} from './ListBoxSection';
23
23
  import {ListState} from '@react-stately/list';
24
- import {mergeProps} from '@react-aria/utils';
24
+ import {mergeProps, useObjectRef} from '@react-aria/utils';
25
25
  import {ProgressCircle} from '@react-spectrum/progress';
26
- import React, {HTMLAttributes, ReactElement, ReactNode, useCallback, useContext, useMemo} from 'react';
26
+ import React, {ForwardedRef, HTMLAttributes, ReactElement, ReactNode, useCallback, useContext, useMemo} from 'react';
27
27
  import {ReusableView} from '@react-stately/virtualizer';
28
28
  import styles from '@adobe/spectrum-css-temp/components/menu/vars.css';
29
29
  import {useLocalizedStringFormatter} from '@react-aria/i18n';
@@ -62,28 +62,31 @@ export function useListBoxLayout<T>(): ListBoxLayout<T> {
62
62
  return layout;
63
63
  }
64
64
 
65
+ // forwardRef doesn't support generic parameters, so cast the result to the correct type
66
+ // https://stackoverflow.com/questions/58469229/react-with-typescript-generics-while-using-react-forwardref
65
67
  /** @private */
66
- function ListBoxBase<T>(props: ListBoxBaseProps<T>, ref: RefObject<HTMLDivElement | null>) {
67
- let {layout, state, shouldFocusOnHover, shouldUseVirtualFocus, domProps = {}, isLoading, showLoadingSpinner = isLoading, onScroll, renderEmptyState} = props;
68
+ export const ListBoxBase = React.forwardRef(function ListBoxBase<T extends object>(props: ListBoxBaseProps<T>, ref: ForwardedRef<HTMLDivElement | null>) {
69
+ let {layout, state, shouldFocusOnHover = false, shouldUseVirtualFocus = false, domProps = {}, isLoading, showLoadingSpinner = isLoading, onScroll, renderEmptyState} = props;
70
+ let objectRef = useObjectRef(ref);
68
71
  let {listBoxProps} = useListBox({
69
72
  ...props,
70
73
  layoutDelegate: layout,
71
74
  isVirtualized: true
72
- }, state, ref);
75
+ }, state, objectRef);
73
76
  let {styleProps} = useStyleProps(props);
74
77
 
75
78
  // This overrides collection view's renderWrapper to support hierarchy of items in sections.
76
79
  // The header is extracted from the children so it can receive ARIA labeling properties.
77
- type View = ReusableView<Node<T>, ReactElement>;
78
- let renderWrapper = useCallback((parent: View, reusableView: View, children: View[], renderChildren: (views: View[]) => ReactElement[]) => {
80
+ type View = ReusableView<Node<T>, ReactNode>;
81
+ let renderWrapper = useCallback((parent: View | null, reusableView: View, children: View[], renderChildren: (views: View[]) => ReactElement[]) => {
79
82
  if (reusableView.viewType === 'section') {
80
83
  return (
81
84
  <ListBoxSection
82
85
  key={reusableView.key}
83
- item={reusableView.content}
84
- layoutInfo={reusableView.layoutInfo}
86
+ item={reusableView.content!}
87
+ layoutInfo={reusableView.layoutInfo!}
85
88
  virtualizer={reusableView.virtualizer}
86
- headerLayoutInfo={children.find(c => c.viewType === 'header')?.layoutInfo}>
89
+ headerLayoutInfo={children.find(c => c.viewType === 'header')?.layoutInfo ?? null}>
87
90
  {renderChildren(children.filter(c => c.viewType === 'item'))}
88
91
  </ListBoxSection>
89
92
  );
@@ -92,7 +95,7 @@ function ListBoxBase<T>(props: ListBoxBaseProps<T>, ref: RefObject<HTMLDivElemen
92
95
  return (
93
96
  <VirtualizerItem
94
97
  key={reusableView.key}
95
- layoutInfo={reusableView.layoutInfo}
98
+ layoutInfo={reusableView.layoutInfo!}
96
99
  virtualizer={reusableView.virtualizer}
97
100
  parent={parent?.layoutInfo}>
98
101
  {reusableView.rendered}
@@ -109,7 +112,7 @@ function ListBoxBase<T>(props: ListBoxBaseProps<T>, ref: RefObject<HTMLDivElemen
109
112
  <Virtualizer
110
113
  {...styleProps}
111
114
  {...mergeProps(listBoxProps, domProps)}
112
- ref={ref}
115
+ ref={objectRef}
113
116
  persistedKeys={persistedKeys}
114
117
  autoFocus={!!props.autoFocus || undefined}
115
118
  scrollDirection="vertical"
@@ -129,28 +132,25 @@ function ListBoxBase<T>(props: ListBoxBaseProps<T>, ref: RefObject<HTMLDivElemen
129
132
  isLoading={isLoading}
130
133
  onLoadMore={props.onLoadMore}
131
134
  onScroll={onScroll}>
132
- {useCallback((type, item: Node<T>) => {
135
+ {useCallback((type, item: Node<T>): ReactNode => {
133
136
  if (type === 'item') {
134
137
  return <ListBoxOption item={item} />;
135
138
  } else if (type === 'loader') {
136
139
  return <LoadingState />;
137
140
  } else if (type === 'placeholder') {
138
141
  return <EmptyState />;
142
+ } else {
143
+ return null;
139
144
  }
140
145
  }, [])}
141
146
  </Virtualizer>
142
147
  </FocusScope>
143
148
  </ListBoxContext.Provider>
144
149
  );
145
- }
146
-
147
- // forwardRef doesn't support generic parameters, so cast the result to the correct type
148
- // https://stackoverflow.com/questions/58469229/react-with-typescript-generics-while-using-react-forwardref
149
- const _ListBoxBase = React.forwardRef(ListBoxBase) as <T>(props: ListBoxBaseProps<T> & {ref?: RefObject<HTMLDivElement | null>}) => ReactElement;
150
- export {_ListBoxBase as ListBoxBase};
150
+ }) as <T>(props: ListBoxBaseProps<T> & {ref?: RefObject<HTMLDivElement | null>}) => ReactElement;
151
151
 
152
152
  function LoadingState() {
153
- let {state} = useContext(ListBoxContext);
153
+ let {state} = useContext(ListBoxContext)!;
154
154
  let stringFormatter = useLocalizedStringFormatter(intlMessages, '@react-spectrum/listbox');
155
155
  return (
156
156
  // aria-selected isn't needed here since this option is not selectable.
@@ -166,7 +166,7 @@ function LoadingState() {
166
166
  }
167
167
 
168
168
  function EmptyState() {
169
- let {renderEmptyState} = useContext(ListBoxContext);
169
+ let {renderEmptyState} = useContext(ListBoxContext)!;
170
170
  let emptyState = renderEmptyState ? renderEmptyState() : null;
171
171
  if (emptyState == null) {
172
172
  return null;
@@ -20,4 +20,4 @@ interface ListBoxContextValue {
20
20
  shouldUseVirtualFocus: boolean
21
21
  }
22
22
 
23
- export const ListBoxContext = React.createContext<ListBoxContextValue>(null);
23
+ export const ListBoxContext = React.createContext<ListBoxContextValue | null>(null);
@@ -32,7 +32,7 @@ export class ListBoxLayout<T> extends ListLayout<T, ListBoxLayoutProps> {
32
32
  let y = this.contentSize.height;
33
33
 
34
34
  if (this.isLoading) {
35
- let rect = new Rect(0, y, this.virtualizer.visibleRect.width, 40);
35
+ let rect = new Rect(0, y, this.virtualizer!.visibleRect.width, 40);
36
36
  let loader = new LayoutInfo('loader', 'loader', rect);
37
37
  let node = {
38
38
  layoutInfo: loader,
@@ -44,7 +44,7 @@ export class ListBoxLayout<T> extends ListLayout<T, ListBoxLayoutProps> {
44
44
  }
45
45
 
46
46
  if (nodes.length === 0) {
47
- let rect = new Rect(0, y, this.virtualizer.visibleRect.width, this.placeholderHeight ?? this.virtualizer.visibleRect.height);
47
+ let rect = new Rect(0, y, this.virtualizer!.visibleRect.width, this.placeholderHeight ?? this.virtualizer!.visibleRect.height);
48
48
  let placeholder = new LayoutInfo('placeholder', 'placeholder', rect);
49
49
  let node = {
50
50
  layoutInfo: placeholder,
@@ -67,6 +67,7 @@ export class ListBoxLayout<T> extends ListLayout<T, ListBoxLayoutProps> {
67
67
  parentKey: node.key,
68
68
  value: null,
69
69
  level: node.level,
70
+ index: node.index,
70
71
  hasChildNodes: false,
71
72
  childNodes: [],
72
73
  rendered: node.rendered,
@@ -81,7 +82,7 @@ export class ListBoxLayout<T> extends ListLayout<T, ListBoxLayoutProps> {
81
82
  y += header.layoutInfo.rect.height;
82
83
 
83
84
  let section = super.buildSection(node, x, y);
84
- section.children.unshift(header);
85
+ section.children!.unshift(header);
85
86
  return section;
86
87
  }
87
88
  }
@@ -36,7 +36,7 @@ export function ListBoxOption<T>(props: OptionProps<T>) {
36
36
  key
37
37
  } = item;
38
38
  let ElementType: React.ElementType = item.props.href ? 'a' : 'div';
39
- let {state, shouldFocusOnHover, shouldUseVirtualFocus} = useContext(ListBoxContext);
39
+ let {state, shouldFocusOnHover, shouldUseVirtualFocus} = useContext(ListBoxContext)!;
40
40
 
41
41
  let ref = useRef<any>(undefined);
42
42
  let {optionProps, labelProps, descriptionProps, isSelected, isDisabled, isFocused} = useOption(
@@ -20,8 +20,9 @@ import styles from '@adobe/spectrum-css-temp/components/menu/vars.css';
20
20
  import {useListBoxSection} from '@react-aria/listbox';
21
21
  import {useLocale} from '@react-aria/i18n';
22
22
 
23
- interface ListBoxSectionProps<T> extends Omit<VirtualizerItemOptions, 'ref'> {
24
- headerLayoutInfo: LayoutInfo,
23
+ interface ListBoxSectionProps<T> extends Omit<VirtualizerItemOptions, 'ref' | 'layoutInfo'> {
24
+ layoutInfo: LayoutInfo,
25
+ headerLayoutInfo: LayoutInfo | null,
25
26
  item: Node<T>,
26
27
  children?: ReactNode
27
28
  }
@@ -34,7 +35,7 @@ export function ListBoxSection<T>(props: ListBoxSectionProps<T>) {
34
35
  'aria-label': item['aria-label']
35
36
  });
36
37
 
37
- let headerRef = useRef(undefined);
38
+ let headerRef = useRef<HTMLDivElement | null>(null);
38
39
  useVirtualizerItem({
39
40
  layoutInfo: headerLayoutInfo,
40
41
  virtualizer,
@@ -42,7 +43,7 @@ export function ListBoxSection<T>(props: ListBoxSectionProps<T>) {
42
43
  });
43
44
 
44
45
  let {direction} = useLocale();
45
- let {state} = useContext(ListBoxContext);
46
+ let {state} = useContext(ListBoxContext)!;
46
47
 
47
48
  return (
48
49
  <Fragment>
@@ -1 +0,0 @@
1
- {"mappings":"AA4DA;;;;;AAIE;;;;AAIA;;;;AAIA;;;;AAIA;;;;AAIA;;;;AAIA;;;;AAQA;;;;AAIA;;;;AAKF;;;;;;;;AAOE;;;;;;;;;;;AAqBE;;;;;AAQF;;;;AAKE;;;;;AAOJ;EACE;;;;EAIE;;;;;AAMJ;;;;;;;;;;AAWA;;;;AAIA;;;;AAIA;;;;;;;;;;;;;AAmBE;;;;;AAMA;;;;AAKF;;;;;;;AAWA;;;;;;;;;;;;;AAgBE;;;;AAIA;;;;AAIA;;;;AAKE;;;;AAKF;;;;AAMF;;;;;;AAMA;;;;;;AAMA;;;;;;AAOA;;;;;;;;;AAaA;;;;;;;;;;;;AAcE;;;;AAGA;;;;AAKF;;;;;AAMA;;;;;;;;;;AAgBE;;;;AAOF;;;;;;AAOA;;;;;;AAOA;;;;;;AAOA;;;;;;AAMA;;;;;;;;AAUA;;;;;;;;AASA;;;;AAGE;;;;;;AAKE;;;;AAKF;;;;;;;;AAOE;;;;;;;;AAQA;;;;;AAIE;;;;;;;;;;AAyBN;;;;;;;AAWA;;;;;AAKA;;;;AAIA;;;;;AAIE;;;;;;AAOA;;;;;AASE;;;;AAKF;;;;AAKA;;;;;;;AACE;;;;AAUJ;;;;AAIA;;;;AAIA;;;;AAIA;;;;;;AAQA;;;;AAIA;;;;;;;;;;AASA;;;;;;;;;;AASA;;;;;;;;;;AASA;;;;;;;;;;AASA;;;;;;;AAKE;;;;AAAA;;;;AAKF;;;;;;;AAKE;;;;AAAA;;;;AAKF;EACE;;;;;EAIA;;;;;;;;;;;;;;;;;;;EAkBE;;;;EAGA;;;;;EAOI;;;;EAIF;;;;;EAXF;;;;;EAOI;;;;EAIF;;;;;EAXF;;;;;EAOI;;;;EAIF;;;;;EAXF;;;;;EAOI;;;;EAIF;;;;;EAXF;;;;;EAOI;;;;EAIF;;;;;EAXF;;;;;EAOI;;;;EAIF","sources":["packages/@adobe/spectrum-css-temp/components/menu/vars.css"],"sourcesContent":["/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\n@import './index.css';\n@import './skin.css';\n"],"names":[],"version":3,"file":"vars.487ba452.css.map"}