Skip to content

fix(drawer): solve the focus caused element jump bug #3703 #4609

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

Closed
wants to merge 1 commit into from

Conversation

ioslh
Copy link

@ioslh ioslh commented Sep 2, 2021

First of all, thank you for your contribution! 😄

New feature please send pull request to feature branch, and rest to master branch. Pull request will be merged after one of collaborators approve. Please makes sure that these form are filled before submitting your pull request, thank you!

[中文版模板 / Chinese template]

This is a ...

  • New feature
  • Bug fix
  • Site / document update
  • Component style update
  • TypeScript definition update
  • Refactoring
  • Code style optimization
  • Branch merge
  • Other (about what?)

What's the background?

This PR is mainly about two issues.

Fix a long existing bug caused by focus

Solve the focus caused element jump first time drawer opening, there is an issue concerning this bug #3703 .

  • At the first time drawer opening, we set visible to true, which will call render twice(maybe another issue needs to be solved). After the first callling drawer is not truly shown in container(getChildToRender called by false), but domFocus is triggered and called.
  • What happened if you call focus on an invisible element? Please refer to this codepen. focus internally called scrollIntoViewIfNeeded , that's why the element jump weirdly, unless you pass { preventScroll: true} to focus as parameter.

And this example don't have to implemented in that tricky way.

Add examples folder to .gitignore

Maybe every maintainer write different example code temporary, don't have to commit that every time, keep in local machine would be better.

@ioslh ioslh changed the base branch from next to master September 2, 2021 15:39
@ioslh ioslh changed the base branch from master to next September 2, 2021 15:39
@tangjinzhou
Copy link
Member

Keep the examples document for now. We will open source all documents soon

Can it be solved by settimeout

@ajuner ajuner requested review from ajuner and removed request for ajuner September 7, 2021 03:54
@@ -142,7 +142,7 @@ const Drawer = defineComponent({
methods: {
domFocus() {
if (this.dom) {
this.dom.focus();
this.dom.focus({ preventScroll: true });
Copy link
Member

Choose a reason for hiding this comment

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

Is it better to change to setTimeout where domFocus is triggered?

Copy link
Author

Choose a reason for hiding this comment

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

I tried, it actually work. Given we found the root cause is calling focus on invisible element without preventScroll, we can fix it by

  • pass preventScroll to focus
  • or guarantee element appeared in viewport before focus called, so yes setTimeout would do the job, but I'm not sure will it cause any other side effects.

And I personally always consider setTimeout to be the last resort to resolve issues if you have any other options.

Copy link
Member

Choose a reason for hiding this comment

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

you are right. but preventScroll will cause breaking change( we need scrollIntoView).
For 2.x, we can use setTimeout resolve it . we will refactor render logic in v3.x.

@github-actions
Copy link

github-actions bot commented Sep 9, 2022

This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 9, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants