-
Notifications
You must be signed in to change notification settings - Fork 2
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
Allow preventing scroll when an element is focused #5
Conversation
4c6aaf8
to
50cb8a7
Compare
Seems like cypress runs the test on an outdated version of webkit. I'm not sure if we can configure a newer webkit version. if (Cypress.browser.name === 'webkit') {
return
} |
The failing test says |
In the meantime I've found out that in the case of webkit, the reported |
The window's scroll position doesn't change when the tests are run inside WebKit. Use the document's scroll values to work around the problem.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, let's go with this. It may be simpler than triggering an event.
Can you add to the README?
We could consider allowing to mark an entire subtree as no-scroll, but I am not sure that would be needed. We could expand to that if the need becomes apparent.
index.js
Outdated
@@ -258,7 +258,8 @@ function applyFocus(direction, origin, target) { | |||
if (isGroup(target)) { | |||
dispatchGroupFocus(direction, origin, target) | |||
} else if ("focus" in target && typeof target.focus === "function") { | |||
target.focus() | |||
const preventScroll = target.hasAttribute("data-focus-preventScroll") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would prefer sticking to kebab-case.
const preventScroll = target.hasAttribute("data-focus-preventScroll") | |
const preventScroll = target.hasAttribute("data-focus-prevent-scroll") |
I've added a
data-focus-preventScroll
attribute to enable specifying elements that should not initiate scrolling when they receive focus.I opted for this instead of dispatching a custom event that can be prevented, because it seemed simpler. What do you think?