Skip to content

Jitsi Meet - Secure, Simple and Scalable Video Conferences that you use as a standalone app or embed in your web application.

feat(input): improve error message association

Joshua Irmerba88514d0f16
diff --git a/react/features/base/ui/components/web/Input.tsx b/react/features/base/ui/components/web/Input.tsx
index cdf70ed6aa..ff6d6c9aa7 100644
--- a/react/features/base/ui/components/web/Input.tsx
+++ b/react/features/base/ui/components/web/Input.tsx
@@ -15,6 +15,7 @@ interface IProps extends IInputProps {
autoFocus?: boolean;
bottomLabel?: string;
className?: string;
+ describedBy?: string;
hiddenDescription?: string; // Text that will be announced by screen readers but not displayed visually.
iconClick?: () => void;
@@ -24,6 +25,7 @@ interface IProps extends IInputProps {
* info (label, error) so that screen reader users don't get lost.
*/
id: string;
+ invalidReason?: 'grammar' | 'spelling' | boolean;
maxLength?: number;
maxRows?: number;
maxValue?: number;
@@ -164,11 +166,13 @@ const Input = React.forwardRef<any, IProps>(({
className,
clearable = false,
disabled,
+ describedBy,
error,
hiddenDescription,
icon,
iconClick,
id,
+ invalidReason,
label,
maxValue,
maxLength,
@@ -201,7 +205,9 @@ const Input = React.forwardRef<any, IProps>(({
const hiddenDescriptionId = `${id}-hidden-description`;
let ariaDescribedById: string | undefined;
- if (bottomLabel) {
+ if (describedBy) {
+ ariaDescribedById = describedBy;
+ } else if (bottomLabel) {
ariaDescribedById = `${id}-description`;
} else if (hiddenDescription) {
ariaDescribedById = hiddenDescriptionId;
@@ -209,6 +215,16 @@ const Input = React.forwardRef<any, IProps>(({
ariaDescribedById = undefined;
}
+ let ariaInvalid: 'grammar' | 'spelling' | boolean | undefined;
+
+ if (invalidReason) {
+ ariaInvalid = invalidReason;
+ } else if (error) {
+ ariaInvalid = error;
+ } else {
+ ariaInvalid = undefined;
+ }
+
return (
<div className = { cx(styles.inputContainer, className) }>
{label && <label
@@ -226,6 +242,7 @@ const Input = React.forwardRef<any, IProps>(({
{textarea ? (
<TextareaAutosize
aria-describedby = { ariaDescribedById }
+ aria-invalid = { ariaInvalid }
aria-label = { accessibilityLabel }
autoComplete = { autoComplete }
autoFocus = { autoFocus }
@@ -247,6 +264,7 @@ const Input = React.forwardRef<any, IProps>(({
) : (
<input
aria-describedby = { ariaDescribedById }
+ aria-invalid = { ariaInvalid }
aria-label = { accessibilityLabel }
autoComplete = { autoComplete }
autoFocus = { autoFocus }
@@ -280,11 +298,12 @@ const Input = React.forwardRef<any, IProps>(({
</button>}
</div>
{bottomLabel && (
- <span
+ <p
+ aria-live = 'polite'
className = { cx(styles.bottomLabel, isMobile && 'is-mobile', error && 'error') }
- id = { `${id}-description` }>
- {bottomLabel}
- </span>
+ id = { `${id}-description` } >
+ { bottomLabel }
+ </p>
)}
{!bottomLabel && hiddenDescription && <HiddenDescription id = { hiddenDescriptionId }>{ hiddenDescription }</HiddenDescription>}
</div>
diff --git a/react/features/prejoin/components/web/Prejoin.tsx b/react/features/prejoin/components/web/Prejoin.tsx
index 5a7e0e7863..e875ad19e5 100644
--- a/react/features/prejoin/components/web/Prejoin.tsx
+++ b/react/features/prejoin/components/web/Prejoin.tsx
@@ -417,12 +417,14 @@ const Prejoin = ({
autoComplete = { 'name' }
autoFocus = { true }
className = { classes.input }
+ describedBy = { showErrorOnField ? 'prejoin-error-missing-name' : undefined }
error = { showErrorOnField }
id = 'premeeting-name-input'
onChange = { setName }
onKeyPress = { showUnsafeRoomWarning && !unsafeRoomConsent ? undefined : onInputKeyPress }
placeholder = { t('dialog.enterDisplayName') }
readOnly = { readOnlyName }
+ required = { true }
value = { name } />
) : (
<div className = { classes.avatarContainer }>
@@ -438,7 +440,9 @@ const Prejoin = ({
{showErrorOnField && <div
className = { classes.error }
data-testid = 'prejoin.errorMessage'>
- <p aria-live = 'polite' >
+ <p
+ aria-live = 'polite'
+ id = 'prejoin-error-missing-name' >
{t('prejoin.errorMissingName')}
</p>
</div>}