Skip to content
Merged
Changes from all 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
31 changes: 30 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 @@ -92,6 +92,7 @@ const TextField = (props: InternalTextFieldProps) => {
readonly = false,
showMandatoryIndication,
clearButtonStyle,
accessibilityLabel: accessibilityLabelProp,
...others
} = usePreset(props);

Expand Down Expand Up @@ -138,9 +139,37 @@ const TextField = (props: InternalTextFieldProps) => {
[typographyStyle, colorStyle, others.style, centeredTextStyle, hasValue]);
const dummyPlaceholderStyle = useMemo(() => [inputStyle, styles.dummyPlaceholder], [inputStyle]);

const defaultAccessibilityLabel = 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 thread
lidord-wix marked this conversation as resolved.

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

return parts.join(', ');
Comment thread
lidord-wix marked this conversation as resolved.
}, [label, context.isMandatory, helperText, placeholder, showCharCounter, others.maxLength]);

const accessibilityLabel = accessibilityLabelProp ?? defaultAccessibilityLabel;

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