Skip to content

Commit 378f853

Browse files
fix(app): improve input field accessibility and aria-description (#439)
Co-authored-by: Darian <darian410@gmail.com>
1 parent f896350 commit 378f853

File tree

2 files changed

+14
-22
lines changed

2 files changed

+14
-22
lines changed

frontend/app/components/redesign/components/InputField.tsx

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ interface InputFieldProps extends InputHTMLAttributes<HTMLInputElement> {
66
id?: string
77
error?: string | string[]
88
helpText?: string
9+
ariaDescription?: string
910
showCounter?: boolean
1011
currentLength?: number
1112
}
@@ -17,6 +18,7 @@ export const InputField = forwardRef<HTMLInputElement, InputFieldProps>(
1718
error,
1819
id,
1920
helpText,
21+
ariaDescription,
2022
showCounter = false,
2123
className = '',
2224
required,
@@ -28,6 +30,8 @@ export const InputField = forwardRef<HTMLInputElement, InputFieldProps>(
2830
) => {
2931
const generatedId = useId()
3032
const fieldId = id || generatedId
33+
const ariaDescriptionId =
34+
ariaDescription && !error ? `${fieldId}-aria-desc` : undefined
3135

3236
const getDisplayError = (): string | string[] | undefined => {
3337
if (required && !props.value) {
@@ -66,9 +70,14 @@ export const InputField = forwardRef<HTMLInputElement, InputFieldProps>(
6670
id={fieldId}
6771
name={fieldId}
6872
aria-invalid={!!error}
69-
aria-describedby={displayError ? 'input-error' : undefined}
73+
aria-describedby={displayError ? 'input-error' : ariaDescriptionId}
7074
{...props}
7175
/>
76+
{ariaDescription && !displayError && (
77+
<p id={ariaDescriptionId} className="sr-only">
78+
{ariaDescription}
79+
</p>
80+
)}
7281

7382
{displayError && (
7483
<span

frontend/app/components/redesign/components/revshare/ShareInput.tsx

Lines changed: 4 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,6 @@ export const ShareInput = React.memo(
160160
onClick={onRemove}
161161
className="border-none p-xs shrink-0"
162162
aria-label="Remove recipient"
163-
aria-describedby={pointerInputId}
164163
>
165164
<SVGDeleteScript className="w-6 h-6" />
166165
</ToolsSecondaryButton>
@@ -177,11 +176,8 @@ export const ShareInput = React.memo(
177176
onChange={(e: React.ChangeEvent<HTMLInputElement>) =>
178177
onChangeName(e.target.value)
179178
}
180-
aria-describedby={`name-description-${index}`}
179+
ariaDescription="Enter an optional name for this recipient"
181180
/>
182-
<div id={`name-description-${index}`} className="sr-only">
183-
Optional name for this recipient.
184-
</div>
185181
</div>
186182
<div
187183
role="cell"
@@ -200,12 +196,7 @@ export const ShareInput = React.memo(
200196
}
201197
required
202198
error={error}
203-
aria-required="true"
204-
aria-invalid={hasError}
205-
aria-describedby={cx(
206-
`pointer-description-${index}`,
207-
hasError ? `pointer-error-${index}` : ''
208-
)}
199+
ariaDescription="Enter a valid wallet address or payment pointer for this recipient"
209200
className={cx(
210201
showIcon && 'pr-10',
211202
hasError && 'border-field-border-error'
@@ -217,9 +208,6 @@ export const ShareInput = React.memo(
217208
{showSuccess && <SVGCheckIcon className="w-4 h-4" />}
218209
</div>
219210
)}
220-
<div id={`pointer-description-${index}`} className="sr-only">
221-
Required wallet address for this recipient.
222-
</div>
223211
</div>
224212
<div role="cell" aria-labelledby="col-weight">
225213
<label htmlFor={weightInputId} className="sr-only">
@@ -235,13 +223,9 @@ export const ShareInput = React.memo(
235223
onChangeWeight(Number(e.target.value))
236224
}
237225
disabled={weightDisabled || (!!pointer && isValid !== true)}
238-
aria-disabled={weightDisabled || (!!pointer && isValid !== true)}
239-
aria-describedby={`weight-description-${index}`}
240-
aria-required="true"
226+
required
227+
ariaDescription="Enter a numeric weight for this recipient. Higher weight values result in a larger percentage of revenue."
241228
/>
242-
<div id={`weight-description-${index}`} className="sr-only">
243-
Weight value for calculating revenue share.
244-
</div>
245229
</div>
246230
<div role="cell" aria-labelledby="col-percentage">
247231
<div
@@ -261,7 +245,6 @@ export const ShareInput = React.memo(
261245
onClick={onRemove}
262246
className="border-none p-xs shrink-0"
263247
aria-label="Remove recipient"
264-
aria-describedby={pointerInputId}
265248
>
266249
<SVGDeleteScript className="w-6 h-6" />
267250
</ToolsSecondaryButton>

0 commit comments

Comments
 (0)