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
8 changes: 5 additions & 3 deletions src/components/Checkbox/Checkbox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
]}
Expand Down
55 changes: 55 additions & 0 deletions src/components/__tests__/Checkbox/Checkbox.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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(
<LocaleProvider direction={direction}>
<Checkbox
status="checked"
onPress={() => {}}
aria-label="Notify me"
/>
</LocaleProvider>
);

/* eslint-disable no-restricted-syntax --
The mark is drawn with borders, without a separate accessible node. */
const findGlyph = (
node: NonNullable<typeof screen.root>
): ViewStyle | undefined => {
const style = StyleSheet.flatten<ViewStyle>(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(
Expand Down
Loading