10
10
* governing permissions and limitations under the License.
11
11
*/
12
12
13
- import { AriaListBoxOptions , AriaListBoxProps , DraggableItemResult , DragPreviewRenderer , DroppableCollectionResult , DroppableItemResult , FocusScope , ListKeyboardDelegate , mergeProps , useCollator , useFocusRing , useHover , useListBox , useListBoxSection , useLocale , useOption } from 'react-aria' ;
13
+ import { AriaListBoxOptions , AriaListBoxProps , DraggableItemResult , DragPreviewRenderer , DroppableCollectionResult , DroppableItemResult , FocusScope , ListKeyboardDelegate , mergeProps , useCollator , useFocusRing , useHover , useListBox , useListBoxSection , useLocale , useOption , OptionAria } from 'react-aria' ;
14
14
import { Collection , CollectionBuilder , createBranchComponent , createLeafComponent } from '@react-aria/collections' ;
15
15
import { CollectionProps , CollectionRendererContext , ItemRenderProps , SectionContext , SectionProps } from './Collection' ;
16
16
import { ContextValue , DEFAULT_SLOT , Provider , RenderProps , ScrollableProps , SlotProps , StyleRenderProps , useContextProps , useRenderProps , useSlot } from './utils' ;
@@ -20,10 +20,11 @@ import {DraggableCollectionState, DroppableCollectionState, ListState, Node, Ori
20
20
import { filterDOMProps , mergeRefs , useObjectRef } from '@react-aria/utils' ;
21
21
import { forwardRefType , HoverEvents , Key , LinkDOMProps , RefObject } from '@react-types/shared' ;
22
22
import { HeaderContext } from './Header' ;
23
- import React , { createContext , ForwardedRef , forwardRef , JSX , ReactNode , useContext , useEffect , useMemo , useRef } from 'react' ;
23
+ import React , { createContext , ForwardedRef , forwardRef , JSX , memo , ReactNode , useContext , useEffect , useMemo , useRef } from 'react' ;
24
24
import { SeparatorContext } from './Separator' ;
25
25
import { TextContext } from './Text' ;
26
26
import { UNSTABLE_InternalAutocompleteContext } from './Autocomplete' ;
27
+ import { SelectionManager } from '@react-stately/selection' ;
27
28
28
29
export interface ListBoxRenderProps {
29
30
/**
@@ -332,13 +333,23 @@ export interface ListBoxItemProps<T = object> extends RenderProps<ListBoxItemRen
332
333
export const ListBoxItem = /*#__PURE__*/ createLeafComponent ( 'item' , function ListBoxItem < T extends object > ( props : ListBoxItemProps < T > , forwardedRef : ForwardedRef < HTMLDivElement > , item : Node < T > ) {
333
334
let ref = useObjectRef < any > ( forwardedRef ) ;
334
335
let state = useContext ( ListStateContext ) ! ;
335
- let { dragAndDropHooks , dragState , dropState } = useContext ( DragAndDropContext ) ! ;
336
- let { optionProps , labelProps , descriptionProps , ... states } = useOption (
336
+
337
+ let options = useOption (
337
338
{ key : item . key , 'aria-label' : props ?. [ 'aria-label' ] } ,
338
339
state ,
339
340
ref
340
341
) ;
341
342
343
+ return < ListBoxItemInner selectionManager = { state . selectionManager } options = { options } focused = { item . key === state . focusedKey } passRef = { ref } props = { props } item = { item } />
344
+ } ) ;
345
+
346
+ const ListBoxItemInner = memo ( function ListBoxItemInner < T extends object > ( { props, item, selectionManager, options, focused, passRef} :
347
+ { options : OptionAria , props : ListBoxItemProps < T > , focused : boolean , selectionManager : SelectionManager , item : Node < T > , passRef : React . MutableRefObject < any > } ) {
348
+ const ref = passRef ;
349
+
350
+ let { dragAndDropHooks, dragState, dropState} = useContext ( DragAndDropContext ) ! ;
351
+ let { optionProps, labelProps, descriptionProps, ...states } = options ;
352
+
342
353
let { hoverProps, isHovered} = useHover ( {
343
354
isDisabled : ! states . allowsSelection && ! states . hasAction ,
344
355
onHoverStart : item . props . onHoverStart ,
@@ -367,8 +378,8 @@ export const ListBoxItem = /*#__PURE__*/ createLeafComponent('item', function Li
367
378
values : {
368
379
...states ,
369
380
isHovered,
370
- selectionMode : state . selectionManager . selectionMode ,
371
- selectionBehavior : state . selectionManager . selectionBehavior ,
381
+ selectionMode : selectionManager . selectionMode ,
382
+ selectionBehavior : selectionManager . selectionBehavior ,
372
383
allowsDragging : ! ! dragState ,
373
384
isDragging,
374
385
isDropTarget : droppableItem ?. isDropTarget
@@ -397,7 +408,7 @@ export const ListBoxItem = /*#__PURE__*/ createLeafComponent('item', function Li
397
408
data-pressed = { states . isPressed || undefined }
398
409
data-dragging = { isDragging || undefined }
399
410
data-drop-target = { droppableItem ?. isDropTarget || undefined }
400
- data-selection-mode = { state . selectionManager . selectionMode === 'none' ? undefined : state . selectionManager . selectionMode } >
411
+ data-selection-mode = { selectionManager . selectionMode === 'none' ? undefined : selectionManager . selectionMode } >
401
412
< Provider
402
413
values = { [
403
414
[ TextContext , {
0 commit comments