Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: add accessibility updates to amount field #7692

Open
wants to merge 5 commits into
base: develop
Choose a base branch
from
Open
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import classNames from 'classnames';
import {__} from '@wordpress/i18n';
import CurrencyInput from 'react-currency-input-field';
import { CurrencyInputOnChangeValues } from "react-currency-input-field/dist/components/CurrencyInputProps";
import {CurrencyInputOnChangeValues} from 'react-currency-input-field/dist/components/CurrencyInputProps';

/**
* @since 3.0.0
Expand All @@ -22,13 +22,15 @@ const decimalSeparator = formatter.format(1.1).replace(/[0-9]/g, '');
/**
* @since 3.0.0
*/
const CustomAmount = (
{defaultValue, fieldError, currency, value, onValueChange}: CustomAmountProps
) => {

const CustomAmount = ({defaultValue, fieldError, currency, value, onValueChange}: CustomAmountProps) => {
return (
<div className={classNames('givewp-fields-amount__input-container', {invalid: fieldError})}>
<CurrencyInput
ref={(input) => {
if (input && fieldError) {
input.focus();
Copy link
Contributor

@jonwaldstein jonwaldstein Feb 7, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmm, i'm pretty sure react-hook-form handles this for us or at least provides a way of doing this for custom inputs. I know it works properly for other fields since we're using shouldFocusOnError by default. Might want to check the discussion forums https://github.com/orgs/react-hook-form/discussions?discussions_q=is%3Aopen+shouldFocusError

There's also a react-hook-form helper setFocus

}
}}
intlConfig={{
locale: navigator.language,
currency,
Expand All @@ -43,14 +45,18 @@ const CustomAmount = (
groupSeparator.replace(/\u00A0/g, ' ')
}
className="givewp-fields-amount__input givewp-fields-amount__input-custom"
aria-label={__('Enter custom amount', 'give')}
aria-describedby={fieldError ? 'givewp-field-error-amount' : undefined}
aria-invalid={fieldError ? 'true' : 'false'}
id="amount-custom"
name="amount-custom"
placeholder={__('Enter custom amount', 'give')}
defaultValue={defaultValue}
value={value}
decimalsLimit={2}
onValueChange={(value) => {onValueChange(value !== undefined ? value : '')}}
onValueChange={(value) => {
onValueChange(value !== undefined ? value : '');
}}
/>
</div>
);
Expand Down
Loading