Skip to content

Commit 93b1d04

Browse files
committed
[fix] CheckBox supports readOnly on native control
Fix #2359
1 parent 107c6ee commit 93b1d04

File tree

4 files changed

+37
-2
lines changed

4 files changed

+37
-2
lines changed

packages/react-native-web-examples/pages/checkbox/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ export default function CheckboxPage() {
2424
<CheckBox disabled style={styles.item} value={false} />
2525
<Divider />
2626
<CheckBox disabled style={styles.item} value={true} />
27+
<Divider />
28+
<CheckBox accessibilityReadOnly style={styles.item} value={true} />
2729
</View>
2830
<View style={styles.row}>
2931
<CheckBox value={false} />

packages/react-native-web/src/exports/CheckBox/__tests__/__snapshots__/index-test.js.snap

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,22 @@ exports[`CheckBox prop "accessibilityLabel" value is set 1`] = `
1515
</div>
1616
`;
1717

18+
exports[`CheckBox prop "accessibilityReadOnly" value is set 1`] = `
19+
<div
20+
aria-readonly="true"
21+
class="css-view-175oi2r r-cursor-1loqt21 r-height-10ptun7 r-userSelect-lrvibr r-width-1janqcz"
22+
>
23+
<div
24+
class="css-view-175oi2r r-alignItems-1awozwy r-backgroundColor-14lw9ot r-borderColor-1awa8pu r-borderRadius-1jkafct r-borderStyle-1phboty r-borderWidth-d045u9 r-height-1pi2tsx r-justifyContent-1777fci r-width-13qz1uu"
25+
/>
26+
<input
27+
class="r-appearance-30o5oe r-bottom-1p0dtai r-height-1pi2tsx r-left-1d2f490 r-margin-crgep1 r-padding-t60dpp r-position-u8s1d r-right-zchlnj r-top-ipm5af r-width-13qz1uu r-cursor-1ei5mc7"
28+
readonly=""
29+
type="checkbox"
30+
/>
31+
</div>
32+
`;
33+
1834
exports[`CheckBox prop "color" value is set 1`] = `
1935
<div
2036
class="css-view-175oi2r r-cursor-1loqt21 r-height-10ptun7 r-userSelect-lrvibr r-width-1janqcz"

packages/react-native-web/src/exports/CheckBox/__tests__/index-test.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,13 @@ describe('CheckBox', () => {
2525
});
2626
});
2727

28+
describe('prop "accessibilityReadOnly"', () => {
29+
test('value is set', () => {
30+
const { container } = render(<CheckBox accessibilityReadOnly={true} />);
31+
expect(container.firstChild).toMatchSnapshot();
32+
});
33+
});
34+
2835
describe('prop "color"', () => {
2936
test('value is set', () => {
3037
const { container } = render(<CheckBox color="lightblue" value={true} />);

packages/react-native-web/src/exports/CheckBox/index.js

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,16 @@ const CheckBox: React.AbstractComponent<
2929
CheckBoxProps,
3030
React.ElementRef<typeof View>
3131
> = React.forwardRef((props, forwardedRef) => {
32-
const { color, disabled, onChange, onValueChange, style, value, ...other } =
33-
props;
32+
const {
33+
accessibilityReadOnly,
34+
color,
35+
disabled,
36+
onChange,
37+
onValueChange,
38+
style,
39+
value,
40+
...other
41+
} = props;
3442

3543
function handleChange(event: Object) {
3644
const value = event.nativeEvent.target.checked;
@@ -56,6 +64,7 @@ const CheckBox: React.AbstractComponent<
5664
checked: value,
5765
disabled: disabled,
5866
onChange: handleChange,
67+
readOnly: accessibilityReadOnly,
5968
ref: forwardedRef,
6069
style: [styles.nativeControl, styles.cursorInherit],
6170
type: 'checkbox'
@@ -65,6 +74,7 @@ const CheckBox: React.AbstractComponent<
6574
<View
6675
{...other}
6776
accessibilityDisabled={disabled}
77+
accessibilityReadOnly={accessibilityReadOnly}
6878
style={[styles.root, style, disabled && styles.cursorDefault]}
6979
>
7080
{fakeControl}

0 commit comments

Comments
 (0)