Skip to content

Commit

Permalink
fix: add support for input props in radio and checkbox
Browse files Browse the repository at this point in the history
  • Loading branch information
segunadebayo committed Mar 14, 2022
1 parent 1221216 commit 02be2bc
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
10 changes: 9 additions & 1 deletion packages/checkbox/src/checkbox.tsx
Expand Up @@ -72,6 +72,10 @@ export interface CheckboxProps
* @default CheckboxIcon
*/
icon?: React.ReactElement
/**
* Additional props to be forwarded to the `input` element
*/
inputProps?: React.InputHTMLAttributes<HTMLInputElement>
}

/**
Expand Down Expand Up @@ -100,6 +104,7 @@ export const Checkbox = forwardRef<CheckboxProps, "input">((props, ref) => {
isChecked: isCheckedProp,
isDisabled = group?.isDisabled,
onChange: onChangeProp,
inputProps,
...rest
} = ownProps

Expand Down Expand Up @@ -150,7 +155,10 @@ export const Checkbox = forwardRef<CheckboxProps, "input">((props, ref) => {
className={cx("chakra-checkbox", className)}
{...getRootProps()}
>
<input className="chakra-checkbox__input" {...getInputProps({}, ref)} />
<input
className="chakra-checkbox__input"
{...getInputProps(inputProps, ref)}
/>
<CheckboxControl
__css={styles.control}
className="chakra-checkbox__control"
Expand Down
7 changes: 6 additions & 1 deletion packages/radio/src/radio.tsx
Expand Up @@ -35,6 +35,10 @@ export interface RadioProps
* please use the props `maxWidth` or `width` to configure
*/
isFullWidth?: boolean
/**
* Additional props to be forwarded to the `input` element
*/
inputProps?: React.InputHTMLAttributes<HTMLInputElement>
}

/**
Expand All @@ -57,6 +61,7 @@ export const Radio = forwardRef<RadioProps, "input">((props, ref) => {
isFullWidth,
isDisabled = group?.isDisabled,
isFocusable = group?.isFocusable,
inputProps: htmlInputProps,
...rest
} = ownProps

Expand Down Expand Up @@ -90,7 +95,7 @@ export const Radio = forwardRef<RadioProps, "input">((props, ref) => {
const [layoutProps, otherProps] = split(htmlProps, layoutPropNames as any)

const checkboxProps = getCheckboxProps(otherProps)
const inputProps = getInputProps({}, ref)
const inputProps = getInputProps(htmlInputProps, ref)
const labelProps = getLabelProps()
const rootProps = Object.assign({}, layoutProps, getRootProps())

Expand Down

0 comments on commit 02be2bc

Please sign in to comment.