Skip to content

Commit

Permalink
fix(ui-checkbox,ui-radio-input): reduce clickable area of checkbox an…
Browse files Browse the repository at this point in the history
…d radioinput

Closes: INSTUI-4197
  • Loading branch information
joyenjoyer committed Sep 10, 2024
1 parent cfa9dc6 commit 77b2a7d
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 44 deletions.
44 changes: 23 additions & 21 deletions packages/ui-checkbox/src/Checkbox/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -273,27 +273,29 @@ class Checkbox extends Component<CheckboxProps, CheckboxState> {
onMouseOut={createChainedFunction(onMouseOut, this.handleMouseOut)}
ref={this.handleRef}
>
<input
{...props}
id={this.id}
value={value}
type="checkbox"
ref={(c) => {
this._input = c
}}
disabled={disabled || readOnly}
aria-checked={indeterminate ? 'mixed' : undefined}
css={styles?.input}
onChange={this.handleChange}
onKeyDown={createChainedFunction(onKeyDown, this.handleKeyDown)}
onFocus={createChainedFunction(onFocus, this.handleFocus)}
onBlur={createChainedFunction(onBlur, this.handleBlur)}
checked={this.checked}
/>
<label htmlFor={this.id} css={styles?.control}>
{this.renderFacade()}
{this.renderMessages()}
</label>
<div css={styles?.container}>
<input
{...props}
id={this.id}
value={value}
type="checkbox"
ref={(c) => {
this._input = c
}}
disabled={disabled || readOnly}
aria-checked={indeterminate ? 'mixed' : undefined}
css={styles?.input}
onChange={this.handleChange}
onKeyDown={createChainedFunction(onKeyDown, this.handleKeyDown)}
onFocus={createChainedFunction(onFocus, this.handleFocus)}
onBlur={createChainedFunction(onBlur, this.handleBlur)}
checked={this.checked}
/>
<label htmlFor={this.id} css={styles?.control}>
{this.renderFacade()}
{this.renderMessages()}
</label>
</div>
</div>
)
}
Expand Down
7 changes: 5 additions & 2 deletions packages/ui-checkbox/src/Checkbox/props.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,12 @@ type AllowedPropKeys = Readonly<Array<PropKeys>>

type CheckboxProps = CheckboxOwnProps &
WithStyleProps<CheckboxFacadeTheme | ToggleFacadeTheme, CheckboxStyle> &
OtherHTMLAttributes<CheckboxOwnProps> & WithDeterministicIdProps
OtherHTMLAttributes<CheckboxOwnProps> &
WithDeterministicIdProps

type CheckboxStyle = ComponentStyle<'checkbox' | 'input' | 'control'>
type CheckboxStyle = ComponentStyle<
'checkbox' | 'input' | 'control' | 'container'
>

const propTypes: PropValidators<PropKeys> = {
label: PropTypes.node.isRequired,
Expand Down
4 changes: 4 additions & 0 deletions packages/ui-checkbox/src/Checkbox/styles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,10 @@ const generateStyle = (
width: 'auto'
})
},
// this container is added to reduce the clickable area of the checkbox to the actual checkbox and label
container: {
width: 'fit-content'
},
input: {
label: 'checkbox__input',
padding: 0,
Expand Down
42 changes: 22 additions & 20 deletions packages/ui-radio-input/src/RadioInput/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -141,26 +141,28 @@ class RadioInput extends Component<RadioInputProps, RadioInputState> {
this.ref = el
}}
>
<input
{...props}
id={this.id}
ref={(c: HTMLInputElement | null) => {
this._input = c
}}
value={value}
name={name}
checked={this.checked}
type="radio"
css={styles?.input}
disabled={disabled || readOnly}
aria-disabled={disabled || readOnly ? 'true' : undefined}
onChange={this.handleChange}
onClick={this.handleClick}
/>
<label css={styles?.control} htmlFor={this.id}>
<span css={styles?.facade} aria-hidden="true" />
<span css={styles?.label}>{label}</span>
</label>
<div css={styles?.container}>
<input
{...props}
id={this.id}
ref={(c: HTMLInputElement | null) => {
this._input = c
}}
value={value}
name={name}
checked={this.checked}
type="radio"
css={styles?.input}
disabled={disabled || readOnly}
aria-disabled={disabled || readOnly ? 'true' : undefined}
onChange={this.handleChange}
onClick={this.handleClick}
/>
<label css={styles?.control} htmlFor={this.id}>
<span css={styles?.facade} aria-hidden="true" />
<span css={styles?.label}>{label}</span>
</label>
</div>
</div>
)
}
Expand Down
2 changes: 1 addition & 1 deletion packages/ui-radio-input/src/RadioInput/props.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ type RadioInputProps = RadioInputOwnProps &
WithDeterministicIdProps

type RadioInputStyle = ComponentStyle<
'radioInput' | 'input' | 'control' | 'facade' | 'label'
'radioInput' | 'input' | 'control' | 'facade' | 'label' | 'container'
>

type RadioInputState = {
Expand Down
4 changes: 4 additions & 0 deletions packages/ui-radio-input/src/RadioInput/styles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,10 @@ const generateStyle = (
...(disabled && { cursor: 'not-allowed' })
}
},
// this container is added to reduce the clickable area to the size of the radio button and label
container: {
width: 'fit-content'
},
input: {
label: 'radioInput__input',
...inputStyles,
Expand Down

0 comments on commit 77b2a7d

Please sign in to comment.