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
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -73,3 +73,5 @@ site/dev.js

# IDE 语法提示临时文件
vetur/

examples/
2 changes: 1 addition & 1 deletion components/vc-drawer/src/Drawer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.

}
},
onKeyDown(e) {
Expand Down
8 changes: 0 additions & 8 deletions examples/App.tsx

This file was deleted.

39 changes: 0 additions & 39 deletions examples/App.vue

This file was deleted.

30 changes: 0 additions & 30 deletions examples/index.html

This file was deleted.

29 changes: 0 additions & 29 deletions examples/index.js

This file was deleted.