MCPcopy Create free account
hub / github.com/adobe/react-spectrum / MenuSection

Function MenuSection

packages/@adobe/react-spectrum/src/menu/MenuSection.tsx:29–81  ·  view source on GitHub ↗
(props: MenuSectionProps<T>)

Source from the content-addressed store, hash-verified

27
28/** @private */
29export function MenuSection<T>(props: MenuSectionProps<T>): JSX.Element {
30 let {item, state} = props;
31 let {itemProps, headingProps, groupProps} = useMenuSection({
32 heading: item.rendered,
33 'aria-label': item['aria-label']
34 });
35
36 let {separatorProps} = useSeparator({
37 elementType: 'div'
38 });
39
40 let firstSectionKey = state.collection.getFirstKey();
41 let lastSectionKey = [...state.collection].filter(node => node.type === 'section').at(-1)?.key;
42 let sectionIsFirst =
43 firstSectionKey === item.key && state.collection.getFirstKey() === firstSectionKey;
44 let lastKey = state.collection.getLastKey();
45 let sectionIsLast =
46 lastSectionKey === item.key &&
47 lastKey != null &&
48 state.collection.getItem(lastKey)!.parentKey === lastSectionKey;
49
50 return (
51 <Fragment>
52 {item.key !== state.collection.getFirstKey() && (
53 <div {...separatorProps} className={classNames(styles, 'spectrum-Menu-divider')} />
54 )}
55 <div {...itemProps}>
56 {item.rendered && (
57 <span {...headingProps} className={classNames(styles, 'spectrum-Menu-sectionHeading')}>
58 {item.rendered}
59 </span>
60 )}
61 <div
62 {...groupProps}
63 className={classNames(styles, 'spectrum-Menu', {
64 'spectrum-Menu-section--noHeading': item.rendered == null,
65 'spectrum-Menu-section--isFirst': sectionIsFirst,
66 'spectrum-Menu-section--isLast': sectionIsLast
67 })}>
68 {[...getChildNodes(item, state.collection)].map(node => {
69 let item = <MenuItem key={node.key} item={node} state={state} />;
70
71 if (node.wrapper) {
72 item = node.wrapper(item);
73 }
74
75 return item;
76 })}
77 </div>
78 </div>
79 </Fragment>
80 );
81}

Callers

nothing calls this directly

Calls 9

useMenuSectionFunction · 0.90
useSeparatorFunction · 0.90
classNamesFunction · 0.90
getChildNodesFunction · 0.90
getFirstKeyMethod · 0.65
atMethod · 0.65
filterMethod · 0.65
getLastKeyMethod · 0.65
getItemMethod · 0.65

Tested by

no test coverage detected