-
Notifications
You must be signed in to change notification settings - Fork 842
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
Short-circuit EuiLink#onClick
if modifier key is pressed
#8341
Comments
Hey @zinckiwi, Just wrangling some context and thoughts here. Since this is mostly related to SPA routing, for reference, this is our current recommendation: https://github.com/elastic/eui/blob/main/wiki/consuming-eui/react-router.md#1-conversion-function-recommended I've see this implemented in a bunch of different ways in Kibana: https://github.com/elastic/kibana/blob/main/src/platform/packages/shared/kbn-router-utils/src/get_router_link_props/index.ts#L38
https://github.com/elastic/kibana/blob/main/src/platform/packages/shared/cloud/connection_details/components/spa_no_router_link/spa_no_router_link.tsx#L24 It's definitely messy and fairly inconsistent. Something like you propose seems helpful and I assume is generally useful regardless of what library you're using for SPA routing (EDIT: Unless your router already provides utilities for this, like Actually, at a glance, I think the larger problem Kibana has at this point is that many folks simply don't provide an href along with their onClick for SPA links, so we end up with a lot of buttons where we want anchors.
I do think we would need to consider edge cases here. I suspect there are times where folks will want to trigger side effects with |
Just thinking that if we added something like |
Is your feature request related to a problem? Please describe.
Cloud UI had a bug report/feature request around the handling of links. In short, when Ctrl/Cmd/Shift-clicking to open an EuiLink in a new window, it doesn't work. This is due to our usage of both
href
andonClick
in EuiLink:onClick
is the main handler so that internal navigation within the app can be handled programmatically (history.push
) for optimal UXhref
is still provided to allow browser native functionality for right-click context menus (e.g. "Open in new tab")We are not, however, consulting the state of any modification keys in the
onClick
handler, so attempting to use a keyboard shortcut doesn't have the intended effect in-browser.Describe the solution you'd like
I propose that
EuiLink#onClick
first guard against modifier keys before invoking the supplied prop callback. If a modifier key is detected, assume that the user wants to open the link in a new destination and therefore programmaticonClick
behaviour is not necessary. If there are foreseeable edge cases, we could also consider an additional prop for fine-grained control (e.g.alwaysUseOnClick?: true | undefined
), but I'm having a hard time coming up with any.Describe alternatives you've considered
The most obvious alternative is to bake this functionality into a wrapper component within Cloud UI, which performs the guard but otherwise passes through to
EuiLink
. However, I think this is a fundamental enough concern that it is naturally coupled to the component that handles the click and makes the distinction between programmatic (onClick
) and native (href
) navigation --EuiLink
.Desired timeline
Open
Additional context
I suspect when I say
EuiLink
I also meanEuiButton
-as-supplied-with-an-href.The text was updated successfully, but these errors were encountered: