From f412e814e929f932d41f062d282b824b92714033 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B0=8F=E8=B1=AA?= <1844749591@qq.com> Date: Mon, 18 Nov 2024 01:22:29 +0800 Subject: [PATCH] feat: improve a11y --- src/index.tsx | 23 ++++------------------- tests/__snapshots__/index.test.tsx.snap | 16 ++++++++-------- 2 files changed, 12 insertions(+), 27 deletions(-) diff --git a/src/index.tsx b/src/index.tsx index 0bf0465..36557ea 100644 --- a/src/index.tsx +++ b/src/index.tsx @@ -1,7 +1,5 @@ import classNames from 'classnames'; import useMergedState from 'rc-util/lib/hooks/useMergedState'; -import omit from 'rc-util/lib/omit'; -import pickAttrs from 'rc-util/lib/pickAttrs'; import * as React from 'react'; import { forwardRef, useImperativeHandle, useRef } from 'react'; @@ -29,8 +27,6 @@ export interface CheckboxProps onChange?: (e: CheckboxChangeEvent) => void; } -const DEFAULT_ARIA_LABEL = 'checkbox'; - export const Checkbox = forwardRef((props, ref) => { const { prefixCls = 'rc-checkbox', @@ -45,18 +41,8 @@ export const Checkbox = forwardRef((props, ref) => { ...inputProps } = props; - const a11yProps = { - ...pickAttrs(inputProps, true), - 'aria-label': inputProps['aria-label'] || DEFAULT_ARIA_LABEL, - } as React.AriaAttributes; - - const restProps = omit, keyof React.AriaAttributes>( - inputProps, - Object.keys(a11yProps) as Array, - ); - const inputRef = useRef(null); - const holderRef = useRef(null); + const holderRef = useRef(null); const [rawValue, setRawValue] = useMergedState(defaultChecked, { value: checked, @@ -104,10 +90,9 @@ export const Checkbox = forwardRef((props, ref) => { }; return ( - + ); }); diff --git a/tests/__snapshots__/index.test.tsx.snap b/tests/__snapshots__/index.test.tsx.snap index 07c12b0..88a68cf 100644 --- a/tests/__snapshots__/index.test.tsx.snap +++ b/tests/__snapshots__/index.test.tsx.snap @@ -1,7 +1,7 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP exports[`rc-checkbox click checkbox 1`] = ` - - + `; exports[`rc-checkbox click radio 1`] = ` - - + `; exports[`rc-checkbox control mode 1`] = ` - - + `; exports[`rc-checkbox works 1`] = ` - - + `;