-
Notifications
You must be signed in to change notification settings - Fork 273
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: *ByA11yState default value false value for busy, disabled & sele…
…cted state (#1166)
- Loading branch information
1 parent
96bf63a
commit bd5ddd7
Showing
6 changed files
with
252 additions
and
73 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import { AccessibilityState } from 'react-native'; | ||
import { ReactTestInstance } from 'react-test-renderer'; | ||
import { accessibilityStateKeys } from '../accessiblity'; | ||
|
||
/** | ||
* Default accessibility state values based on experiments using accessibility | ||
* inspector/screen reader on iOS and Android. | ||
* | ||
* @see https://github.com/callstack/react-native-testing-library/wiki/Accessibility:-State | ||
*/ | ||
const defaultState: AccessibilityState = { | ||
disabled: false, | ||
selected: false, | ||
checked: undefined, | ||
busy: false, | ||
expanded: undefined, | ||
}; | ||
|
||
export function matchAccessibilityState( | ||
node: ReactTestInstance, | ||
matcher: AccessibilityState | ||
) { | ||
const state = node.props.accessibilityState; | ||
return accessibilityStateKeys.every((key) => matchState(state, matcher, key)); | ||
} | ||
|
||
function matchState( | ||
state: AccessibilityState, | ||
matcher: AccessibilityState, | ||
key: keyof AccessibilityState | ||
) { | ||
return ( | ||
matcher[key] === undefined || | ||
matcher[key] === (state?.[key] ?? defaultState[key]) | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.