Repository navigation
feat(swiftui): add A2UITextFieldStyle for the Basic Catalog TextField - #4361
Conversation
Add A2UITextFieldStyle, A2UITextFieldStyleConfiguration and View.a2uiTextFieldStyle(_:), following A2UIButtonStyle and A2UICardStyle. DefaultA2UITextFieldStyle (.automatic) keeps the current look. The configuration carries the label, the input control, the variant, the first failing error check message and the disabled state. The input keeps its data binding and accessibility modifiers under any style, and A2UITextField still renders the check message below the styled field. Part of a2ui-project#3257.
Add a test that hosts A2UITextField under a custom A2UITextFieldStyle and reads the accessibility label and hint of the a2ui-<id> element from the platform accessibility tree, with and without an explicit accessibility label. Also restore the DocC symbol links in the new style files, add the blank line after their license headers, drop the unused OrderedJSON import from A2UITextField.swift and a no-op modifier from the README example.
There was a problem hiding this comment.
Code Review
This pull request introduces customizable styling for A2UITextField components in BasicCatalogSwiftUI by adding A2UITextFieldStyle, A2UITextFieldStyleConfiguration, and the a2uiTextFieldStyle view modifier. It refactors A2UITextField to delegate its layout and rendering to the resolved style, provides a default implementation, and includes comprehensive tests. Feedback on the changes suggests removing redundant .accessibilityIdentifier modifiers within the input view builder of A2UITextFieldStyleConfiguration.Field to simplify the code.
Field.body already sets the identifier on the whole input.
…d-style # Conflicts: # swift/CHANGELOG.md
|
Hi @karolkulesza, Thank you for raising the pr to fix the issue. We have verified the pr and it does resolve the issue. I will escalate this to team to review. Thank you for your patience and understanding. |
…d-style # Conflicts: # swift/CHANGELOG.md
pinieb
left a comment
There was a problem hiding this comment.
Thanks for picking up A2UITextFieldStyle, @karolkulesza! The protocol design, DynamicProperty environment resolution, and accessibility preservation on Field align cleanly with A2UIButtonStyle and A2UICardStyle.
A few things to update before merging:
- Let styles own the full body (including
checkMessage): Rather than keeping an outerVStackinA2UITextField, letA2UITextFieldpass straight through toA2UITextFieldStyleHost, moveA2UICheckMessageintoDefaultA2UITextFieldStyle, and expose a composablecheckMessageview onA2UITextFieldStyleConfiguration. That lets custom styles control full layout and validation UI without risking duplicate error messages fromerrorMessage. We opened #4461 to track a composableA2UICheckMessageStyleseparately, so there is no need to implement check styling here. - Minor cleanup & test coverage: Drop the duplicate
.accessibilityIdentifieronField.body, use@accessibilityin the v1.0 accessibility test, and add assertions verifying check message rendering and two-wayvaluebinding / reactive validation updates under a custom style.
A2UITextField now passes straight through to its style. A2UITextFieldStyleConfiguration gains a checkMessage view wrapping A2UICheckMessage, and DefaultA2UITextFieldStyle renders it below the field, so a custom style controls the whole layout and can leave the message out to present errorMessage its own way. Drops the identifier that a2uiAccessibilityControl already sets on the field, uses @accessibility in the v1.0 accessibility test, and adds assertions for the check message under the built-in and custom styles and a hosted test that typing under a custom style writes the bound value and updates the checks the style sees.
pinieb
left a comment
There was a problem hiding this comment.
Thanks for making those updates, @karolkulesza!
Verified in 2cbef774:
A2UITextFieldpasses straight through toA2UITextFieldStyleHost,A2UITextFieldStyleConfigurationexposescheckMessage, andDefaultA2UITextFieldStylerenders it below the input—giving custom styles full layout control while keepingREADME.md,CHANGELOG.md, and DocC comments up to date.- Dropped the redundant
.accessibilityIdentifieronField.bodyand switchedcustomTextFieldStyleKeepsInputAccessibilityto@accessibility. - The expanded
ComponentStyleTestsnow verify.automaticacross all four variants, optional rendering ofconfiguration.checkMessage, and end-to-end typing and reactive check updates under a custom style viaHostedViewDriver.
Looks great—ready to merge once the remaining Swift Core (iOS) test job goes green!
Problem
#3257 asks for a way to restyle the SwiftUI Basic Catalog components. #4024 added
A2UIButtonStyleandA2UICardStyle, and the issue stays open forText,TextFieldandImage.A2UITextFieldstill hard-codes its look: 10 pt padding, a gray fill, an 8 pt corner radius, and a border and label that turn red while a check fails. To change that, an app has to replace the whole component, copying the data binding, the variants and the accessibility modifiers.Part of #3257. This PR covers
TextFieldonly.TextandImageare also changed by the open #4123.Changes
Adds
A2UITextFieldStyle,A2UITextFieldStyleConfigurationandView.a2uiTextFieldStyle(_:)toBasicCatalogSwiftUI, built the same way asA2UIButtonStylein feat(swift): add A2UICardStyle, A2UIButtonStyle, and Surface.makeWithBasicCatalogs #4024. The protocol refinesDynamicPropertyand the style is resolved through a generic wrapper view, so a style's@Environmentvalues (such as\.colorScheme) resolve.The configuration has:
label: the label text, ornilwhen thelabelproperty is empty. It stays hidden from assistive technologies, as before.field: the input control for the variant (SecureFieldforobscured, a verticalTextFieldforlongText, the decimal pad on iOS fornumber), bound tovalueand carrying the accessibility identifier, label and hint.variant(shortText,longText,number,obscured; unknown values resolve toshortText),errorMessage(the first failingerrorcheck) withhasError,isDisabled(from the environment'sisEnabled), andnode.DefaultA2UITextFieldStyle(.automatic) draws whatA2UITextFielddrew before, with the same values.A2UITextFieldstill rendersA2UICheckMessagebelow the style's view, so errors and warning/info hints look the same under any style. The accessibility modifiers moved from the padded box onto the input control, so a custom style can't drop them. They still reach the same native text field.The style is read in a private host view inside
A2UITextField.body, so tests that call.bodyoutside a hosted view don't read the environment.New tests in
ComponentStyleTests:shortText, and an ancestor.disabled(true)setsisDisabled;\.colorSchemein Dark Mode inside aSurface;a2ui-<id>element in the platform accessibility tree has the explicit accessibility label and hint, or thelabelproperty when there is no explicit label.The existing
A2UITextField, check message, accessibility and adapter conformance tests pass unchanged.A "Styling Basic Catalog components" section in
swift/README.mdwith a text field style example, and aswift/CHANGELOG.mdentry.Verified on macOS (Xcode toolchain, Swift 6.1 package):
swift buildswift test --enable-swift-testing --no-parallel --filter A2UISwiftUITests: 203 tests. All pass exceptA2UIModalTests.keyboardActivationOfButtonTriggerRunsActionOnceAndPresentsSheet, which also fails onmainwhen run headless.swift test --enable-swift-testing --no-parallel --skip A2UISwiftUITests: 809 tests pass.scripts/fix_format.sh --check --only-swiftandswift-format lint --stricton the changed files.Pre-launch Checklist
One time:
For this PR:
If you need help, consider asking for advice on the discussion board.