@@ -92,6 +92,8 @@ const TextField = (props: InternalTextFieldProps) => {
9292 readonly = false ,
9393 showMandatoryIndication,
9494 clearButtonStyle,
95+ testID,
96+ accessibilityLabel : accessibilityLabelProp ,
9597 ...others
9698 } = usePreset ( props ) ;
9799
@@ -138,9 +140,38 @@ const TextField = (props: InternalTextFieldProps) => {
138140 [ typographyStyle , colorStyle , others . style , centeredTextStyle , hasValue ] ) ;
139141 const dummyPlaceholderStyle = useMemo ( ( ) => [ inputStyle , styles . dummyPlaceholder ] , [ inputStyle ] ) ;
140142
143+ const defaultAccessibilityLabel = useMemo ( ( ) => {
144+ const parts : string [ ] = [ ] ;
145+
146+ if ( label ) {
147+ parts . push ( label ) ;
148+ }
149+
150+ if ( context . isMandatory ) {
151+ parts . push ( 'required' ) ;
152+ }
153+
154+ parts . push ( 'textField' ) ;
155+
156+ if ( helperText ) {
157+ parts . push ( helperText ) ;
158+ } else if ( placeholder ) {
159+ parts . push ( placeholder ) ;
160+ }
161+
162+ if ( showCharCounter && others . maxLength ) {
163+ parts . push ( `you can enter up to ${ others . maxLength } characters` ) ;
164+ }
165+
166+ return parts . join ( ', ' ) ;
167+
168+ } , [ label , context . isMandatory , helperText , placeholder , showCharCounter , others . maxLength ] ) ;
169+
170+ const accessibilityLabel = accessibilityLabelProp ?? defaultAccessibilityLabel ;
171+
141172 return (
142173 < FieldContext . Provider value = { context } >
143- < View { ...containerProps } style = { [ margins , positionStyle , containerStyle , centeredContainerStyle ] } >
174+ < View { ...containerProps } testID = { testID } accessible accessibilityLabel = { accessibilityLabel } style = { [ margins , positionStyle , containerStyle , centeredContainerStyle ] } >
144175 < View row spread style = { centeredContainerStyle } >
145176 < Label
146177 label = { label }
@@ -149,7 +180,7 @@ const TextField = (props: InternalTextFieldProps) => {
149180 labelProps = { labelProps }
150181 floatingPlaceholder = { floatingPlaceholder }
151182 validationMessagePosition = { validationMessagePosition }
152- testID = { `${ props . testID } .label` }
183+ testID = { `${ testID } .label` }
153184 showMandatoryIndication = { showMandatoryIndication }
154185 enableErrors = { enableErrors }
155186 />
@@ -160,7 +191,7 @@ const TextField = (props: InternalTextFieldProps) => {
160191 validationMessage = { others . validationMessage }
161192 validationMessageStyle = { _validationMessageStyle }
162193 retainValidationSpace = { retainValidationSpace && retainTopMessageSpace }
163- testID = { `${ props . testID } .validationMessage` }
194+ testID = { `${ testID } .validationMessage` }
164195 />
165196 ) }
166197 { topTrailingAccessory && < View > { topTrailingAccessory } </ View > }
@@ -189,7 +220,7 @@ const TextField = (props: InternalTextFieldProps) => {
189220 floatOnFocus = { floatOnFocus }
190221 validationMessagePosition = { validationMessagePosition }
191222 extraOffset = { leadingAccessoryMeasurements ?. width }
192- testID = { `${ props . testID } .floatingPlaceholder` }
223+ testID = { `${ testID } .floatingPlaceholder` }
193224 showMandatoryIndication = { showMandatoryIndication }
194225 />
195226 ) }
@@ -198,6 +229,7 @@ const TextField = (props: InternalTextFieldProps) => {
198229 placeholderTextColor = { hidePlaceholder ? 'transparent' : placeholderTextColor }
199230 value = { fieldState . value }
200231 { ...others }
232+ testID = { `${ testID } .input` }
201233 readonly = { readonly }
202234 style = { inputStyle }
203235 onFocus = { onFocus }
@@ -212,7 +244,7 @@ const TextField = (props: InternalTextFieldProps) => {
212244 { showClearButton && (
213245 < ClearButton
214246 onClear = { onClear }
215- testID = { `${ props . testID } .clearButton` }
247+ testID = { `${ testID } .clearButton` }
216248 onChangeText = { onChangeText }
217249 clearButtonStyle = { clearButtonStyle }
218250 />
@@ -230,11 +262,11 @@ const TextField = (props: InternalTextFieldProps) => {
230262 validationIcon = { validationIcon }
231263 validationMessageStyle = { _validationMessageStyle }
232264 retainValidationSpace = { retainValidationSpace }
233- testID = { `${ props . testID } .validationMessage` }
265+ testID = { `${ testID } .validationMessage` }
234266 />
235267 ) }
236268 { helperText && (
237- < Text $textNeutralHeavy subtext marginT-s1 testID = { `${ props . testID } .helperText` } >
269+ < Text $textNeutralHeavy subtext marginT-s1 testID = { `${ testID } .helperText` } >
238270 { helperText }
239271 </ Text >
240272 ) }
@@ -245,7 +277,7 @@ const TextField = (props: InternalTextFieldProps) => {
245277 < CharCounter
246278 maxLength = { others . maxLength }
247279 charCounterStyle = { charCounterStyle }
248- testID = { `${ props . testID } .charCounter` }
280+ testID = { `${ testID } .charCounter` }
249281 />
250282 ) }
251283 </ View >
0 commit comments