Skip to content
28 changes: 27 additions & 1 deletion packages/react-native-ui-lib/src/components/textField/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -138,9 +138,35 @@ const TextField = (props: InternalTextFieldProps) => {
[typographyStyle, colorStyle, others.style, centeredTextStyle, hasValue]);
const dummyPlaceholderStyle = useMemo(() => [inputStyle, styles.dummyPlaceholder], [inputStyle]);

const accessibilityLabel = useMemo(() => {
const parts: string[] = [];

if (label) {
parts.push(label);
}

if (context.isMandatory) {
parts.push('required');
}

parts.push('textField');

if (helperText) {
parts.push(helperText);
} else if (placeholder) {
parts.push(placeholder);
}
Comment on lines +156 to +158
Copy link
Collaborator

Choose a reason for hiding this comment

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

Have we decided to include the placeholder? it can also be some weird example..

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

That's what Alexey said in the case helper text is empty :|


if (showCharCounter && others.maxLength) {
parts.push(`you can enter up to ${others.maxLength} characters`);
}

return parts.join(', ');
Copy link
Collaborator

Choose a reason for hiding this comment

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

Seems like it will work, for English :)
What about other languages?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Should I use i18n? Do I need to change something with the reading order of the label in other languages?

}, [label, context.isMandatory, helperText, placeholder, showCharCounter, others.maxLength]);

return (
<FieldContext.Provider value={context}>
<View {...containerProps} style={[margins, positionStyle, containerStyle, centeredContainerStyle]}>
<View {...containerProps} accessible accessibilityLabel={accessibilityLabel} style={[margins, positionStyle, containerStyle, centeredContainerStyle]}>
<View row spread style={centeredContainerStyle}>
<Label
label={label}
Expand Down