Skip to content

Commit

Permalink
fix: editable check only for TextInput and wording
Browse files Browse the repository at this point in the history
  • Loading branch information
HugoChollet committed Dec 9, 2022
1 parent 5e0cda3 commit 0b3de92
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 8 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -119,11 +119,11 @@ toBeDisabled();

Check whether or not an element is disabled from a user perspective.

This matcher will check if the element or its parent has any of thoses props value:
This matcher will check if the element or its parent has any of those props :

- `disabled={true}`
- `accessibilityState={{disabled: true}}`
- `editable={false}`
- `editable={false}` for `TextInput` only

It also works with `accessibilityStates={['disabled']}` for now. However, this prop is deprecated in
React Native [0.62](https://reactnative.dev/blog/2020/03/26/version-0.62#breaking-changes)
Expand Down
8 changes: 4 additions & 4 deletions src/__tests__/to-be-disabled.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,9 @@ describe('.toBeDisabled', () => {
});
});

test('handle editable prop for TextInput when false', () => {
test('handle editable prop for TextInput', () => {
const { queryByTestId } = render(
<View testID="view">
<View>
<TextInput testID="disabled" editable={false} />
<TextInput testID="enabled" editable />
</View>,
Expand Down Expand Up @@ -92,9 +92,9 @@ describe('.toBeEnabled', () => {
});
});

test('handle editable prop for TextInput when true', () => {
test('handle editable prop for TextInput', () => {
const { queryByTestId } = render(
<View testID="view">
<View>
<TextInput testID="enabled-by-default" />
<TextInput testID="enabled" editable />
<TextInput testID="disabled" editable={false} />
Expand Down
6 changes: 4 additions & 2 deletions src/to-be-disabled.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,14 @@ const DISABLE_TYPES = [

function isElementDisabled(element: ReactTestInstance) {
if (!DISABLE_TYPES.includes(getType(element))) return false;
if (getType(element) === 'TextInput' && element?.props?.editable === false) {
return true;
}

return (
!!element?.props?.disabled ||
!!element?.props?.accessibilityState?.disabled ||
!!element?.props?.accessibilityStates?.includes('disabled') ||
element?.props?.editable === false
!!element?.props?.accessibilityStates?.includes('disabled')
);
}

Expand Down

0 comments on commit 0b3de92

Please sign in to comment.