Skip to content

Commit b9e2ad7

Browse files
committed
fix cases where extra separators appeared on combobox filter/if load sentinel is present
1 parent 4637d34 commit b9e2ad7

File tree

2 files changed

+15
-9
lines changed

2 files changed

+15
-9
lines changed

packages/@react-aria/collections/src/CollectionBuilder.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -157,9 +157,9 @@ function useSSRCollectionNode<T extends Element>(Type: string, props: object, re
157157
return <Type ref={itemRef}>{children}</Type>;
158158
}
159159

160-
export function createLeafComponent<T extends object, P extends object, E extends Element>(type: string, render: (props: P, ref: ForwardedRef<E>) => ReactElement): (props: P & React.RefAttributes<T>) => ReactElement | null;
161-
export function createLeafComponent<T extends object, P extends object, E extends Element>(type: string, render: (props: P, ref: ForwardedRef<E>, node: Node<T>) => ReactElement): (props: P & React.RefAttributes<T>) => ReactElement | null;
162-
export function createLeafComponent<P extends object, E extends Element>(type: string, render: (props: P, ref: ForwardedRef<E>, node?: any) => ReactElement): (props: P & React.RefAttributes<any>) => ReactElement | null {
160+
export function createLeafComponent<T extends object, P extends object, E extends Element>(type: string, render: (props: P, ref: ForwardedRef<E>) => ReactElement | null): (props: P & React.RefAttributes<T>) => ReactElement | null;
161+
export function createLeafComponent<T extends object, P extends object, E extends Element>(type: string, render: (props: P, ref: ForwardedRef<E>, node: Node<T>) => ReactElement | null): (props: P & React.RefAttributes<T>) => ReactElement | null;
162+
export function createLeafComponent<P extends object, E extends Element>(type: string, render: (props: P, ref: ForwardedRef<E>, node?: any) => ReactElement | null): (props: P & React.RefAttributes<any>) => ReactElement | null {
163163
let Component = ({node}) => render(node.props, node.props.ref, node);
164164
let Result = (forwardRef as forwardRefType)((props: P, ref: ForwardedRef<E>) => {
165165
let focusableProps = useContext(FocusableContext);
@@ -190,7 +190,7 @@ export function createLeafComponent<P extends object, E extends Element>(type: s
190190
return Result;
191191
}
192192

193-
export function createBranchComponent<T extends object, P extends {children?: any}, E extends Element>(type: string, render: (props: P, ref: ForwardedRef<E>, node: Node<T>) => ReactElement, useChildren: (props: P) => ReactNode = useCollectionChildren): (props: P & React.RefAttributes<E>) => ReactElement | null {
193+
export function createBranchComponent<T extends object, P extends {children?: any}, E extends Element>(type: string, render: (props: P, ref: ForwardedRef<E>, node: Node<T>) => ReactElement | null, useChildren: (props: P) => ReactNode = useCollectionChildren): (props: P & React.RefAttributes<E>) => ReactElement | null {
194194
let Component = ({node}) => render(node.props, node.props.ref, node);
195195
let Result = (forwardRef as forwardRefType)((props: P, ref: ForwardedRef<E>) => {
196196
let children = useChildren(props);

packages/@react-spectrum/s2/src/ComboBox.tsx

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import {
2626
ListBoxItemProps,
2727
ListBoxProps,
2828
ListLayout,
29+
ListStateContext,
2930
Provider,
3031
SectionProps,
3132
UNSTABLE_ListBoxLoadingSentinel,
@@ -56,6 +57,7 @@ import {IconContext} from './Icon';
5657
// @ts-ignore
5758
import intlMessages from '../intl/*.json';
5859
import {mergeRefs, useResizeObserver, useSlotId} from '@react-aria/utils';
60+
import {Node} from 'react-stately';
5961
import {Placement} from 'react-aria';
6062
import {PopoverBase} from './Popover';
6163
import {pressScale} from './pressScale';
@@ -278,10 +280,7 @@ export let listboxHeader = style<{size?: 'S' | 'M' | 'L' | 'XL'}>({
278280
});
279281

280282
const separatorWrapper = style({
281-
display: {
282-
':is(:last-child > *)': 'none',
283-
default: 'flex'
284-
},
283+
display: 'flex',
285284
marginX: {
286285
size: {
287286
S: `[${edgeToText(24)}]`,
@@ -694,7 +693,14 @@ const ComboboxInner = forwardRef(function ComboboxInner(props: ComboBoxProps<any
694693
);
695694
});
696695

697-
export const Divider = /*#__PURE__*/ createLeafComponent('separator', function Divider({size}: {size?: 'S' | 'M' | 'L' | 'XL'}, ref: ForwardedRef<HTMLDivElement>) {
696+
export const Divider = /*#__PURE__*/ createLeafComponent('separator', function Divider({size}: {size?: 'S' | 'M' | 'L' | 'XL'}, ref: ForwardedRef<HTMLDivElement>, node: Node<unknown>) {
697+
let listState = useContext(ListStateContext)!;
698+
699+
let nextNode = node.nextKey != null && listState.collection.getItem(node.nextKey);
700+
if (node.prevKey == null || !nextNode || nextNode.type === 'separator' || (nextNode.type === 'loader' && nextNode.nextKey == null)) {
701+
return null;
702+
}
703+
698704
return (
699705
<div className={separatorWrapper({size})}>
700706
<div ref={ref} className={dividerStyle} />

0 commit comments

Comments
 (0)