Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -439,6 +439,8 @@ export default class RNPickerSelect extends PureComponent {
left: 4,
}}
{...touchableDoneProps}
accessibilityRole="button"
accessibilityLabel={doneText}
>
<View testID="needed_for_touchable">
<Text
Expand Down Expand Up @@ -507,9 +509,11 @@ export default class RNPickerSelect extends PureComponent {
}

renderIOS() {
const { style, modalProps, pickerProps, touchableWrapperProps } = this.props;
const { disabled, style, modalProps, pickerProps, touchableWrapperProps } = this.props;
const { animationType, orientation, selectedItem, showPicker } = this.state;

const accessibilityLabel = pickerProps && pickerProps.accessibilityLabel;

return (
<View style={[defaultStyles.viewContainer, style.viewContainer]}>
<TouchableOpacity
Expand All @@ -519,6 +523,10 @@ export default class RNPickerSelect extends PureComponent {
}}
activeOpacity={1}
{...touchableWrapperProps}
accessible
accessibilityRole="combobox"
accessibilityLabel={accessibilityLabel}
accessibilityState={{ disabled, expanded: showPicker }}
>
{this.renderTextInputOrChildren()}
</TouchableOpacity>
Expand Down
102 changes: 102 additions & 0 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -657,6 +657,108 @@ describe("RNPickerSelect", () => {
});
});

describe("iOS mode accessibility", () => {
beforeEach(() => {
Platform.OS = "ios";
});

it("should have accessibility props on the wrapper (iOS)", () => {
const wrapper = shallow(
<RNPickerSelect
items={selectItems}
onValueChange={noop}
pickerProps={{
accessibilityLabel: "Select a language",
}}
/>,
);

const touchable = wrapper.find('[testID="ios_touchable_wrapper"]');

expect(touchable.props().accessible).toEqual(true);
expect(touchable.props().accessibilityRole).toEqual("combobox");
expect(touchable.props().accessibilityLabel).toEqual("Select a language");
expect(touchable.props().accessibilityState).toEqual({ disabled: false, expanded: false });
});

it("should use accessibilityLabel from pickerProps (iOS)", () => {
const wrapper = shallow(
<RNPickerSelect
items={selectItems}
onValueChange={noop}
pickerProps={{
accessibilityLabel: "Choose a color",
}}
/>,
);

const touchable = wrapper.find('[testID="ios_touchable_wrapper"]');

expect(touchable.props().accessibilityLabel).toEqual("Choose a color");
});

it("should have undefined accessibilityLabel when not provided via pickerProps (iOS)", () => {
const wrapper = shallow(
<RNPickerSelect items={selectItems} onValueChange={noop} />,
);

const touchable = wrapper.find('[testID="ios_touchable_wrapper"]');

expect(touchable.props().accessibilityLabel).toBeUndefined();
});

it("should set accessibilityState.expanded to true when picker is open (iOS)", () => {
const wrapper = shallow(
<RNPickerSelect items={selectItems} onValueChange={noop} />,
);

wrapper.find('[testID="ios_touchable_wrapper"]').simulate("press");

const touchable = wrapper.find('[testID="ios_touchable_wrapper"]');

expect(touchable.props().accessibilityState).toEqual({ disabled: false, expanded: true });
});

it("should set accessibilityState.disabled to true when disabled (iOS)", () => {
const wrapper = shallow(
<RNPickerSelect items={selectItems} onValueChange={noop} disabled />,
);

const touchable = wrapper.find('[testID="ios_touchable_wrapper"]');

expect(touchable.props().accessibilityState).toEqual({ disabled: true, expanded: false });
});

it("should have accessibilityRole button on Done button (iOS)", () => {
const wrapper = shallow(
<RNPickerSelect items={selectItems} onValueChange={noop} />,
);

wrapper.find('[testID="ios_touchable_wrapper"]').simulate("press");

const doneButton = wrapper.find('[testID="done_button"]');

expect(doneButton.props().accessibilityRole).toEqual("button");
expect(doneButton.props().accessibilityLabel).toEqual("Done");
});

it("should use custom doneText as accessibilityLabel on Done button (iOS)", () => {
const wrapper = shallow(
<RNPickerSelect
items={selectItems}
onValueChange={noop}
doneText="Confirm"
/>,
);

wrapper.find('[testID="ios_touchable_wrapper"]').simulate("press");

const doneButton = wrapper.find('[testID="done_button"]');

expect(doneButton.props().accessibilityLabel).toEqual("Confirm");
});
});

it("should call the onClose callback when set", () => {
Platform.OS = "ios";
const onCloseSpy = jest.fn();
Expand Down
Loading