[fix] Switch uses aria-label on native control

Close #2559
Fix #2549
This commit is contained in:
tarunrajput
2023-07-17 14:54:17 +05:30
committed by Nicolas Gallagher
parent a8a0c1763b
commit 213b616b3c
2 changed files with 3 additions and 2 deletions
@@ -23,7 +23,7 @@ function findSwitchThumb(container) {
describe('components/Switch', () => { describe('components/Switch', () => {
test('accessibilityLabel is applied to native checkbox', () => { test('accessibilityLabel is applied to native checkbox', () => {
const { container } = render(<Switch accessibilityLabel="switch" />); const { container } = render(<Switch aria-label="switch" />);
expect(findCheckbox(container).getAttribute('aria-label')).toBe('switch'); expect(findCheckbox(container).getAttribute('aria-label')).toBe('switch');
}); });
+2 -1
View File
@@ -44,6 +44,7 @@ const Switch: React.AbstractComponent<
React.ElementRef<typeof View> React.ElementRef<typeof View>
> = React.forwardRef((props, forwardedRef) => { > = React.forwardRef((props, forwardedRef) => {
const { const {
'aria-label': ariaLabel,
accessibilityLabel, accessibilityLabel,
activeThumbColor, activeThumbColor,
activeTrackColor, activeTrackColor,
@@ -166,7 +167,7 @@ const Switch: React.AbstractComponent<
]; ];
const nativeControl = createElement('input', { const nativeControl = createElement('input', {
accessibilityLabel, 'aria-label': ariaLabel || accessibilityLabel,
checked: value, checked: value,
disabled: disabled, disabled: disabled,
onBlur: handleFocusState, onBlur: handleFocusState,