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

fix(components): [input] lose focus when click suffix icon #13264

Merged
merged 6 commits into from
Jul 13, 2023
Merged

Conversation

tolking
Copy link
Member

@tolking tolking commented Jun 18, 2023

fix #13153, close #13159

When click on the prefix or suffix icon, it causes the input to lose focus and then regain focus, resulting in unnecessary loss of focus behavior, This PR has corrected this behavior.

before

after

Please make sure these boxes are checked before submitting your PR, thank you!

  • Make sure you follow contributing guide English | (中文 | Español | Français).
  • Make sure you are merging your commits to dev branch.
  • Add some descriptions and refer to relative issues for your PR.

Description

🤖 Generated by Copilot at 7b9db8c

This pull request introduces a new useFocusController hook that simplifies the focus and blur logic of input components. It also updates the tests and the implementation of the input, input-number, and select components to use this hook. The hook avoids unnecessary blur events when clicking on prefix or suffix elements and provides callbacks for custom focus and blur actions.

Related Issue

Fixes #___.

Explanation of Changes

🤖 Generated by Copilot at 7b9db8c

  • Add useFocusController hook to handle focus and blur events of input elements (link, link, link, link, link, link)
  • Replace original focus and blur logic in input.vue with useFocusController hook (link, link)
    • The hook is imported from @element-plus/hooks module (link)
    • The wrapperRef is bound to the div element with the wrapperKls class using the ref attribute (link)
    • The triggerAttrs are bound to the span element with the nsInput.e('suffix-inner') class using the v-bind directive (link)
  • Add sleep calls to input-number.test.tsx and input.test.tsx to wait for asynchronous updates and events (link, link, link, link)
  • Increase delay argument of sleep call in select.test.ts to ensure blur event is emitted (link)

@github-actions
Copy link

github-actions bot commented Jun 18, 2023

@github-actions github-actions bot added the CommitMessage::Qualified Qualified commit message label Jun 18, 2023
@github-actions
Copy link

github-actions bot commented Jun 18, 2023

🧪 Playground Preview: https://element-plus.run/?pr=13264
Please comment the example via this playground if needed.

@chenxch chenxch merged commit 704399f into dev Jul 13, 2023
10 checks passed
@chenxch chenxch deleted the fix/input-focus branch July 13, 2023 08:41
@element-bot element-bot mentioned this pull request Jul 14, 2023
3 tasks
@purepear
Copy link
Contributor

Looks like this is adding role="button" and tabindex attributes to ElInput 🤔
This can be observed in the docs https://element-plus.org/en-US/component/input.html#basic-usage

This is potential problem for accessibility and tests that use getByRole() might start failing.

image

@tolking
Copy link
Member Author

tolking commented Jul 19, 2023

The role="button" and tabindex only capture focus events from the mouse.

I do not think this will cause accessibility issues, but I am really sorry for the testing and I have not thought of any other alternative methods at the moment.

consultation-applio pushed a commit to consultation-applio/element-plus that referenced this pull request Nov 10, 2023
…lus#13264)

* feat(hooks): add useFocusController

* fix(components): [input] lose focus when click suffix icon

closed element-plus#13153, element-plus#13159

* refactor(hooks): use-focus-controller

* test: fix test

* test: update

* fix(theme-chalk): [input] add cursor style to the wrapper
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CommitMessage::Qualified Qualified commit message
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Component] [select] Select 选择器 点击icon 无法收回弹出层
4 participants