Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(checkbox): add readonly and other accessibles for checkboxes #2360

Closed
wants to merge 1 commit into from
Closed
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
40 changes: 32 additions & 8 deletions packages/react-native-web/src/exports/CheckBox/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ import type { ViewProps } from '../View';

import * as React from 'react';
import createElement from '../createElement';
import * as forwardedProps from '../../modules/forwardedProps';
import pick from '../../modules/pick';
import StyleSheet from '../StyleSheet';
import View from '../View';

Expand All @@ -25,6 +27,27 @@ type CheckBoxProps = {
value?: boolean
};

const forwardPropsList = Object.assign(
{},
forwardedProps.defaultProps,
forwardedProps.accessibilityProps,
forwardedProps.clickProps,
forwardedProps.focusProps,
forwardedProps.keyboardProps,
forwardedProps.mouseProps,
forwardedProps.touchProps,
forwardedProps.styleProps,
{
readOnly: true,
checked: true,
disabled: true,
onChange: true,
type: true
}
);

const pickProps = (props) => pick(props, forwardPropsList);

const CheckBox: React.AbstractComponent<
CheckBoxProps,
React.ElementRef<typeof View>
Expand Down Expand Up @@ -52,14 +75,15 @@ const CheckBox: React.AbstractComponent<
/>
);

const nativeControl = createElement('input', {
checked: value,
disabled: disabled,
onChange: handleChange,
ref: forwardedRef,
style: [styles.nativeControl, styles.cursorInherit],
type: 'checkbox'
});
const supportedProps = pickProps(props);
supportedProps.checked = value;
supportedProps.disabled = disabled;
supportedProps.onChange = handleChange;
supportedProps.ref = forwardedRef;
supportedProps.style = [styles.nativeControl, styles.cursorInherit];
supportedProps.type = 'checkbox';

const nativeControl = createElement('input', supportedProps);

return (
<View
Expand Down