Skip to content

Commit 602aa40

Browse files
authored
Picker left/right arrows shouldn't scroll containers (#1540)
1 parent d9cc6a6 commit 602aa40

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

packages/@react-aria/select/src/useSelect.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,13 +71,19 @@ export function useSelect<T>(props: AriaSelectOptions<T>, state: SelectState<T>,
7171
let onKeyDown = (e: KeyboardEvent) => {
7272
switch (e.key) {
7373
case 'ArrowLeft': {
74+
// prevent scrolling containers
75+
e.preventDefault();
76+
7477
let key = state.selectedKey != null ? delegate.getKeyAbove(state.selectedKey) : delegate.getFirstKey();
7578
if (key) {
7679
state.setSelectedKey(key);
7780
}
7881
break;
7982
}
8083
case 'ArrowRight': {
84+
// prevent scrolling containers
85+
e.preventDefault();
86+
8187
let key = state.selectedKey != null ? delegate.getKeyBelow(state.selectedKey) : delegate.getFirstKey();
8288
if (key) {
8389
state.setSelectedKey(key);

packages/@react-spectrum/picker/stories/Picker.stories.tsx

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import React, {useState} from 'react';
2424
import {storiesOf} from '@storybook/react';
2525
import {Text} from '@react-spectrum/text';
2626
import {useAsyncList} from '@react-stately/data';
27+
import {View} from '@react-spectrum/view';
2728

2829

2930
let flatOptions = [
@@ -499,8 +500,8 @@ storiesOf('Picker', module)
499500
() => (
500501
<AsyncLoadingExample />
501502
)
502-
).add(
503-
'focus',
503+
).add(
504+
'focus',
504505
() => (
505506
<div style={{display: 'flex', width: 'auto', margin: '250px 0'}}>
506507
<input placeholder="Shift tab here" />
@@ -518,6 +519,17 @@ storiesOf('Picker', module)
518519
<Item key="Two">Two</Item>
519520
<Item key="Three">Three</Item>
520521
</Picker>
522+
))
523+
.add('scrolling container', () => (
524+
<View width="300px" height="size-500" overflow="auto">
525+
<View width="500px">
526+
<Picker label="Test" autoFocus>
527+
<Item key="One">One</Item>
528+
<Item key="Two">Two</Item>
529+
<Item key="Three">Three</Item>
530+
</Picker>
531+
</View>
532+
</View>
521533
));
522534

523535
function AsyncLoadingExample() {

0 commit comments

Comments
 (0)