Skip to content

Commit cd6dcec

Browse files
committed
fix: code
1 parent e2ca631 commit cd6dcec

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

packages/react/select/src/select.tsx

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,6 @@ import type { Scope } from '@radix-ui/react-context';
2727

2828
type Direction = 'ltr' | 'rtl';
2929

30-
const startTransition = React.startTransition
31-
? React.startTransition
32-
: window.requestAnimationFrame;
3330
const OPEN_KEYS = [' ', 'Enter', 'ArrowUp', 'ArrowDown'];
3431
const SELECTION_KEYS = [' ', 'Enter'];
3532

@@ -1272,8 +1269,13 @@ const SelectItem = React.forwardRef<SelectItemElement, SelectItemProps>(
12721269

12731270
const handleSelect = () => {
12741271
if (!disabled) {
1275-
context.onValueChange(value);
1276-
context.onOpenChange(false);
1272+
const startTransition = React.startTransition
1273+
? React.startTransition
1274+
: window.requestAnimationFrame;
1275+
startTransition(() => {
1276+
context.onValueChange(value);
1277+
context.onOpenChange(false);
1278+
});
12771279
}
12781280
};
12791281

@@ -1316,12 +1318,12 @@ const SelectItem = React.forwardRef<SelectItemElement, SelectItemProps>(
13161318
onBlur={composeEventHandlers(itemProps.onBlur, () => setIsFocused(false))}
13171319
onClick={composeEventHandlers(itemProps.onClick, () => {
13181320
// Open on click when using a touch or pen device
1319-
if (pointerTypeRef.current !== 'mouse') startTransition(() => handleSelect());
1321+
if (pointerTypeRef.current !== 'mouse') handleSelect();
13201322
})}
13211323
onPointerUp={composeEventHandlers(itemProps.onPointerUp, () => {
13221324
// Using a mouse you should be able to do pointer down, move through
13231325
// the list, and release the pointer over the item to select it.
1324-
if (pointerTypeRef.current === 'mouse') startTransition(() => handleSelect());
1326+
if (pointerTypeRef.current === 'mouse') handleSelect();
13251327
})}
13261328
onPointerDown={composeEventHandlers(itemProps.onPointerDown, (event) => {
13271329
pointerTypeRef.current = event.pointerType;
@@ -1345,7 +1347,7 @@ const SelectItem = React.forwardRef<SelectItemElement, SelectItemProps>(
13451347
onKeyDown={composeEventHandlers(itemProps.onKeyDown, (event) => {
13461348
const isTypingAhead = contentContext.searchRef?.current !== '';
13471349
if (isTypingAhead && event.key === ' ') return;
1348-
if (SELECTION_KEYS.includes(event.key)) startTransition(() => handleSelect());
1350+
if (SELECTION_KEYS.includes(event.key)) handleSelect();
13491351
// prevent page scroll if using the space key to select an item
13501352
if (event.key === ' ') event.preventDefault();
13511353
})}

0 commit comments

Comments
 (0)