diff --git a/src/components/Checkbox/Checkbox.tsx b/src/components/Checkbox/Checkbox.tsx index 194c436a27..2670a67d7a 100644 --- a/src/components/Checkbox/Checkbox.tsx +++ b/src/components/Checkbox/Checkbox.tsx @@ -558,9 +558,11 @@ const Checkbox = ({ style={[ styles.checkmarkGlyph, { borderColor: visual.iconColor }, - // Native platforms auto-swap border sides in RTL, so - // pre-swap them to preserve the checkmark orientation. - direction === 'rtl' && Platform.OS !== 'web' + // Preserve the native RTL pre-swap except on iOS, + // where the physical borders are not swapped back. + direction === 'rtl' && + Platform.OS !== 'web' && + Platform.OS !== 'ios' ? styles.checkmarkGlyphRTL : null, ]} diff --git a/src/components/__tests__/Checkbox/Checkbox.test.tsx b/src/components/__tests__/Checkbox/Checkbox.test.tsx index b8ecd0e92f..5d7eb52dc4 100644 --- a/src/components/__tests__/Checkbox/Checkbox.test.tsx +++ b/src/components/__tests__/Checkbox/Checkbox.test.tsx @@ -3,10 +3,12 @@ import { Platform, Pressable, StyleSheet, + type ViewStyle, } from 'react-native'; import { afterEach, describe, expect, it, jest } from '@jest/globals'; +import { LocaleProvider } from '../../../core/locale'; import { fireEvent, render, screen, userEvent } from '../../../test-utils'; import { tokens } from '../../../theme/tokens'; import Checkbox from '../../Checkbox'; @@ -27,6 +29,59 @@ it('renders checked Checkbox with onPress', async () => { expect(tree).toMatchSnapshot(); }); +describe('Checkbox checkmark direction', () => { + it.each<['ios' | 'android' | 'web', 'ltr' | 'rtl', 'left' | 'right']>([ + ['ios', 'rtl', 'left'], + ['ios', 'ltr', 'left'], + ['android', 'rtl', 'right'], + ['android', 'ltr', 'left'], + ['web', 'rtl', 'left'], + ])( + 'draws the short stroke on the correct side for %s in %s', + async (os, direction, side) => { + jest.replaceProperty(Platform, 'OS', os); + + await render( + + {}} + aria-label="Notify me" + /> + + ); + + /* eslint-disable no-restricted-syntax -- + The mark is drawn with borders, without a separate accessible node. */ + const findGlyph = ( + node: NonNullable + ): ViewStyle | undefined => { + const style = StyleSheet.flatten(node.props.style); + if (style?.borderBottomWidth && style.transform) return style; + return node.children + .map((child) => + typeof child === 'string' ? undefined : findGlyph(child) + ) + .find(Boolean); + }; + /* eslint-enable no-restricted-syntax */ + + const glyph = findGlyph(screen.getByRole('checkbox')); + + expect(screen.getByRole('checkbox', { checked: true })).toBeOnTheScreen(); + expect(glyph).toBeDefined(); + expect( + side === 'left' ? glyph?.borderLeftWidth : glyph?.borderRightWidth + ).toBeGreaterThan(0); + expect( + side === 'left' + ? (glyph?.borderRightWidth ?? 0) + : (glyph?.borderLeftWidth ?? 0) + ).toBe(0); + } + ); +}); + it('renders unchecked Checkbox with onPress', async () => { const tree = ( await render(