Skip to content

Commit

Permalink
feat: improve a11y (#292)
Browse files Browse the repository at this point in the history
* feat: improve a11y

* feat: improve a11y

* feat: improve a11y

* fix: label fix
  • Loading branch information
aojunhao123 authored Nov 19, 2024
1 parent 818d219 commit d3de52f
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 11 deletions.
8 changes: 5 additions & 3 deletions src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,12 @@ export const Checkbox = forwardRef<CheckboxRef, CheckboxProps>((props, ref) => {
type = 'checkbox',
title,
onChange,
children,
...inputProps
} = props;

const inputRef = useRef<HTMLInputElement>(null);
const holderRef = useRef<HTMLElement>(null);
const holderRef = useRef<HTMLLabelElement>(null);

const [rawValue, setRawValue] = useMergedState(defaultChecked, {
value: checked,
Expand Down Expand Up @@ -90,7 +91,7 @@ export const Checkbox = forwardRef<CheckboxRef, CheckboxProps>((props, ref) => {
};

return (
<span className={classString} title={title} style={style} ref={holderRef}>
<label className={classString} title={title} style={style} ref={holderRef}>
<input
{...inputProps}
className={`${prefixCls}-input`}
Expand All @@ -101,7 +102,8 @@ export const Checkbox = forwardRef<CheckboxRef, CheckboxProps>((props, ref) => {
type={type}
/>
<span className={`${prefixCls}-inner`} />
</span>
{children !== undefined && <span>{children}</span>}
</label>
);
});

Expand Down
16 changes: 8 additions & 8 deletions tests/__snapshots__/index.test.tsx.snap
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`rc-checkbox click checkbox 1`] = `
<span
<label
class="rc-checkbox"
>
<input
Expand All @@ -11,11 +11,11 @@ exports[`rc-checkbox click checkbox 1`] = `
<span
class="rc-checkbox-inner"
/>
</span>
</label>
`;

exports[`rc-checkbox click radio 1`] = `
<span
<label
class="rc-checkbox rc-checkbox-checked"
>
<input
Expand All @@ -25,11 +25,11 @@ exports[`rc-checkbox click radio 1`] = `
<span
class="rc-checkbox-inner"
/>
</span>
</label>
`;

exports[`rc-checkbox control mode 1`] = `
<span
<label
class="rc-checkbox rc-checkbox-checked"
>
<input
Expand All @@ -40,11 +40,11 @@ exports[`rc-checkbox control mode 1`] = `
<span
class="rc-checkbox-inner"
/>
</span>
</label>
`;

exports[`rc-checkbox works 1`] = `
<span
<label
class="rc-checkbox"
>
<input
Expand All @@ -54,5 +54,5 @@ exports[`rc-checkbox works 1`] = `
<span
class="rc-checkbox-inner"
/>
</span>
</label>
`;

0 comments on commit d3de52f

Please sign in to comment.