Skip to content

Commit b34ca24

Browse files
committed
fix: do not override native aria-describedby #388
1 parent 889d86a commit b34ca24

File tree

5 files changed

+35
-11
lines changed

5 files changed

+35
-11
lines changed

src/Input.tsx

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,14 @@ export const Input = memo(
177177
classes.nativeInputOrTextArea
178178
)}
179179
disabled={disabled || undefined}
180-
aria-describedby={state !== "default" ? messageId : undefined}
180+
aria-describedby={
181+
[
182+
state !== "default" ? messageId : undefined,
183+
nativeInputOrTextAreaProps["aria-describedby"]
184+
]
185+
.filter(value => value !== undefined)
186+
.join(" ") || undefined
187+
}
181188
type={textArea ? undefined : nativeInputProps?.type ?? "text"}
182189
id={inputId}
183190
/>

src/Select.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,11 @@ export const Select = memo(
104104
{...nativeSelectProps}
105105
className={cx(fr.cx("fr-select"), nativeSelectProps.className)}
106106
id={selectId}
107-
aria-describedby={stateDescriptionId}
107+
aria-describedby={
108+
nativeSelectProps["aria-describedby"] !== undefined
109+
? `${stateDescriptionId} ${nativeSelectProps["aria-describedby"]}`
110+
: stateDescriptionId
111+
}
108112
disabled={disabled}
109113
>
110114
{children}

src/SelectNext.tsx

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,8 @@ function NonMemoizedNonForwardedSelect<T extends SelectProps.Option[]>(
9595
className,
9696
label,
9797
hint,
98-
nativeSelectProps,
99-
disabled = nativeSelectProps?.disabled ?? false,
98+
nativeSelectProps = {},
99+
disabled = nativeSelectProps.disabled ?? false,
100100
options,
101101
state = "default",
102102
stateRelatedMessage,
@@ -113,7 +113,7 @@ function NonMemoizedNonForwardedSelect<T extends SelectProps.Option[]>(
113113
});
114114

115115
const { selectId, stateDescriptionId } = (function useClosure() {
116-
const selectIdExplicitlyProvided = nativeSelectProps?.id;
116+
const selectIdExplicitlyProvided = nativeSelectProps.id;
117117
const elementId = useId();
118118
const selectId = selectIdExplicitlyProvided ?? `select-${elementId}`;
119119
const stateDescriptionId =
@@ -171,9 +171,13 @@ function NonMemoizedNonForwardedSelect<T extends SelectProps.Option[]>(
171171
})()
172172
};
173173
})()}
174-
className={cx(fr.cx("fr-select"), nativeSelectProps?.className)}
174+
className={cx(fr.cx("fr-select"), nativeSelectProps.className)}
175175
id={selectId}
176-
aria-describedby={stateDescriptionId}
176+
aria-describedby={
177+
nativeSelectProps["aria-describedby"] !== undefined
178+
? `${stateDescriptionId} ${nativeSelectProps["aria-describedby"]}`
179+
: stateDescriptionId
180+
}
177181
disabled={disabled}
178182
>
179183
{[

src/Upload.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,11 @@ export const Upload = memo(
7979
</label>
8080
)}
8181
<input
82-
aria-describedby={messageId}
82+
aria-describedby={
83+
nativeInputProps["aria-describedby"] !== undefined
84+
? `${messageId} ${nativeInputProps["aria-describedby"]}`
85+
: messageId
86+
}
8387
aria-disabled={disabled}
8488
className={cx(fr.cx("fr-upload"))}
8589
disabled={disabled}

src/blocks/PasswordInput.tsx

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ export const PasswordInput = memo(
6060
classes = {},
6161
style,
6262
messages = [],
63-
nativeInputProps,
63+
nativeInputProps = {},
6464
messagesHint = t("your password must contain"),
6565
...rest
6666
} = props;
@@ -75,7 +75,7 @@ export const PasswordInput = memo(
7575
const inputId = (function useClosure() {
7676
const id = useId();
7777

78-
return nativeInputProps?.id ?? `password-${id}`;
78+
return nativeInputProps.id ?? `password-${id}`;
7979
})();
8080
const togglePasswordShowId = `${inputId}-toggle-show`;
8181
const messagesGroupId = `${inputId}-messages-group`;
@@ -152,7 +152,12 @@ export const PasswordInput = memo(
152152
id={inputId}
153153
type={isPasswordReveled ? "text" : "password"}
154154
disabled={disabled}
155-
{...(messages.length !== 0 && { "aria-describedby": messagesGroupId })}
155+
{...(messages.length !== 0 && {
156+
"aria-describedby":
157+
nativeInputProps["aria-describedby"] !== undefined
158+
? `${messagesGroupId} ${nativeInputProps["aria-describedby"]}`
159+
: messagesGroupId
160+
})}
156161
/>
157162
</div>
158163
{messages.length !== 0 && (

0 commit comments

Comments
 (0)