Skip to content
Open
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
30 changes: 29 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,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);
}

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

return parts.join(', ');
}, [label, context.isMandatory, helperText, placeholder, showCharCounter, others.maxLength]);

const accessibilityLabel = props.accessibilityLabel ?? defaultAccessibilityLabel;
Copy link
Collaborator

Choose a reason for hiding this comment

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

you can extract the prop like all other props instead of using props.


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