Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(form): focus first failed element #45739

Open
wants to merge 1 commit into
base: feature
Choose a base branch
from

Conversation

Anuovec
Copy link

@Anuovec Anuovec commented Nov 8, 2023

[中文版模板 / Chinese template]

🤔 This is a ...

  • New feature
  • Bug fix
  • Site / documentation update
  • Demo update
  • Component style update
  • TypeScript definition update
  • Bundle size optimization
  • Performance optimization
  • Enhancement feature
  • Internationalization
  • Refactoring
  • Code style optimization
  • Test Case
  • Branch merge
  • Workflow
  • Other (about what?)

🔗 Related issue link

Reference: #45701

💡 Background and solution

While the scrollToFirstError property provides a smooth scroll to the first field that encounters a validation error, it does not automatically set focus to this field. This can be a hindrance to accessibility, as users who rely on keyboard navigation will not automatically know which field has the error, especially after the page scrolls. Moreover, for screen reader users, the error message might not be read out if the focus does not shift to the input with the error.

📝 Changelog

Language Changelog
🇺🇸 English Auto-focus on first field with error on submit
🇨🇳 Chinese Auto-focus on first field with error on submit

☑️ Self-Check before Merge

⚠️ Please check all items below before requesting a reviewing. ⚠️

  • Doc is updated/provided or not needed
  • Demo is updated/provided or not needed
  • TypeScript definition is updated/provided or not needed
  • Changelog is provided or not needed

🚀 Summary

🤖 Generated by Copilot at 7e93b23

This pull request adds a new feature to the Form component and the useForm hook that allows users to focus a form field automatically or manually. It also updates the tests and the documentation for both the English and Chinese versions.

🔍 Walkthrough

🤖 Generated by Copilot at 7e93b23

  • Add a new prop focusFirstErrorField to the Form component, which enables focusing the first failed field when the form validation fails (link, link, link, link, link)
  • Implement the focusField method in the useForm hook, which finds and focuses the field by its name path and id (link, link)
  • Add a test case for the focusFirstErrorField prop in the components/form/__tests__/index.test.tsx file, which asserts that the input element has focus and the onFinishFailed callback is called (link)

Signed-off-by: Tibinko <tibor.hanesz@gmail.com>
Copy link

stackblitz bot commented Nov 8, 2023

Review PR in StackBlitz Codeflow Run & review this pull request in StackBlitz Codeflow.

Copy link
Contributor

github-actions bot commented Nov 8, 2023

Preview Is ready

Copy link

codesandbox-ci bot commented Nov 8, 2023

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

Latest deployment of this branch, based on commit 7e93b23:

Sandbox Source
antd reproduction template (forked) Configuration

Copy link

argos-ci bot commented Nov 8, 2023

The latest updates on your projects. Learn more about Argos notifications ↗︎

Build Status Details Updated (UTC)
default (Inspect) ✅ No change detected - Nov 8, 2023, 6:30 PM

Copy link

codecov bot commented Nov 8, 2023

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (66df407) 100.00% compared to head (7e93b23) 100.00%.

Additional details and impacted files
@@            Coverage Diff            @@
##           feature    #45739   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files          705       705           
  Lines        11996     12003    +7     
  Branches      3191      3194    +3     
=========================================
+ Hits         11996     12003    +7     
Files Coverage Δ
components/form/Form.tsx 100.00% <100.00%> (ø)
components/form/hooks/useForm.ts 100.00% <100.00%> (ø)

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant