From 820539a6b9c0ce3e110e149fbfbc424b84420aeb Mon Sep 17 00:00:00 2001 From: Pareder Date: Wed, 24 Dec 2025 16:53:34 +0200 Subject: [PATCH] fix: prevent aria props from being passed to wrapper div --- src/BaseSelect/index.tsx | 6 ++++- src/SelectInput/index.tsx | 5 ++++- src/hooks/useBaseProps.ts | 1 - tests/Accessibility.test.tsx | 28 ++++++++++++++++++++++++ tests/Select.test.tsx | 3 +-- tests/__snapshots__/Select.test.tsx.snap | 3 --- 6 files changed, 38 insertions(+), 8 deletions(-) diff --git a/src/BaseSelect/index.tsx b/src/BaseSelect/index.tsx index cb2ac94a6..1c65c2501 100644 --- a/src/BaseSelect/index.tsx +++ b/src/BaseSelect/index.tsx @@ -129,7 +129,11 @@ export interface BaseSelectPrivateProps { export type BaseSelectPropsWithoutPrivate = Omit; -export interface BaseSelectProps extends BaseSelectPrivateProps, React.AriaAttributes { +export interface BaseSelectProps + extends + BaseSelectPrivateProps, + React.AriaAttributes, + Pick, 'role'> { // Style className?: string; style?: React.CSSProperties; diff --git a/src/SelectInput/index.tsx b/src/SelectInput/index.tsx index 799809560..6a11895a0 100644 --- a/src/SelectInput/index.tsx +++ b/src/SelectInput/index.tsx @@ -11,6 +11,7 @@ import { clsx } from 'clsx'; import type { ComponentsConfig } from '../hooks/useComponents'; import { getDOM } from '@rc-component/util/lib/Dom/findDOMNode'; import { composeRef } from '@rc-component/util/lib/ref'; +import pickAttrs from '@rc-component/util/lib/pickAttrs'; export interface SelectInputRef { focus: (options?: FocusOptions) => void; @@ -207,6 +208,8 @@ export default React.forwardRef(function Selec // ===================== Render ===================== const domProps = omit(restProps, DEFAULT_OMIT_PROPS as any); + const ariaProps = pickAttrs(domProps, { aria: true }); + const ariaKeys = Object.keys(ariaProps) as (keyof typeof domProps)[]; // Create context value with wrapped callbacks const contextValue = { @@ -228,7 +231,7 @@ export default React.forwardRef(function Selec return (
void; - role?: React.AriaRole; } export const BaseSelectContext = React.createContext(null); diff --git a/tests/Accessibility.test.tsx b/tests/Accessibility.test.tsx index 379405614..364cc37d6 100644 --- a/tests/Accessibility.test.tsx +++ b/tests/Accessibility.test.tsx @@ -213,6 +213,34 @@ describe('Select.Accessibility', () => { } }); }); + + it('should pass aria and role attributes to Input component', async () => { + const { container } = render( +