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

Dont interfere with outside handlers #115

Merged
merged 4 commits into from
Apr 1, 2023

Conversation

floscr
Copy link
Contributor

@floscr floscr commented Mar 30, 2023

When focusing on the resizehandler and resizing with the keyboard, outside event keyhandlers would be executed as well.

@vercel
Copy link

vercel bot commented Mar 30, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
react-resizable-panels ✅ Ready (Inspect) Visit Preview 💬 Add feedback Apr 1, 2023 4:51pm

@@ -82,6 +82,7 @@ export function useWindowSplitterPanelGroupBehavior({
handle.setAttribute("aria-valuenow", "" + Math.round(parseInt(flexGrow)));

const onKeyDown = (event: KeyboardEvent) => {
event.stopPropagation();
Copy link
Owner

Choose a reason for hiding this comment

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

I don't think this is the right fix.

Maybe the "Enter" case below should call event.preventDefault() to signal that it's handled the event, but I don't think it the component should swallow all keyboard events. Can you explain why you think that change is needed?

Copy link
Contributor Author

@floscr floscr Mar 30, 2023

Choose a reason for hiding this comment

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

My issue is that I have an key up listener outside of the component like here (global shortcuts):
https://codesandbox.io/s/react-resizable-panels-forked-vywou9

When resizing via the keyboard, the outside listener get's triggered as well.

event.preventDefault() would not resolve the issue.

Another option would be to be able to pass in a custom onKeyUp handler from the outside and handle it from the consumer side?

Copy link
Owner

@bvaughn bvaughn Mar 30, 2023

Choose a reason for hiding this comment

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

event.preventDefault() would not resolve the issue.

Your key handler would need to respect event.defaultPrevented

Another option would be to be able to pass in a custom onKeyUp handler from the outside and handle it from the consumer side?

This doesn't sound like something I'd want to add. Feels like it adds unnecessary complexity to the API of this component.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Interesting, I've never encountered this approach.
It works, but it's hard to introduce this change in a giant code base, where this wasn't previously considered (which is of course not your responsibility, just trying to provide context 😸 ).

Right now this is blocking me from using this library, as I can't even disable the focus ability or change the handlers.

Copy link
Owner

Choose a reason for hiding this comment

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

I think defaultPrevented would be a reasonable strategy here to signal that the event has already been "handled". Alternately you could block this event in your own code by wrapping the resize handle, e.g.

<div onKeyDown={trapEvent}>
  <PanelResizeHandle {...props} />
</div>

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah that's also a solution, thank you!
I'm investigating how to include defaultPrevented and think it's a good way to go, I've changed the line in the PR now!

Copy link
Owner

@bvaughn bvaughn left a comment

Choose a reason for hiding this comment

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

I think we shouldn't claim events as handled (event.preventDefault) unless we actually handle them.

@bvaughn
Copy link
Owner

bvaughn commented Apr 2, 2023

Published in 0.0.38

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.

2 participants