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

[EuiListGroupItem] Allow onClick with href #1668

Closed
flash1293 opened this issue Mar 5, 2019 · 18 comments
Closed

[EuiListGroupItem] Allow onClick with href #1668

flash1293 opened this issue Mar 5, 2019 · 18 comments
Assignees

Comments

@flash1293
Copy link
Contributor

It isn't possible to provide both href and onClick to an EuiListGroupItem element - the onClick prop will be ignored.

@cchaos
Copy link
Contributor

cchaos commented Mar 5, 2019

@flash1293 Can you explain a situation when you'd need both. It seems to me that they'd conflict with each other. Is it a link or a button?

href and onClick don't exist as attributes of a single HTML element type. We're just allowing one or the other and we'll use an anchor tag or a button tag appropriately depending on whether the href or onClick is present.

@cchaos
Copy link
Contributor

cchaos commented Mar 5, 2019

Edited above href and onClick do exist -> href and onClick don't exist

@flash1293
Copy link
Contributor Author

@cchaos It is necessary for the "Open Search" panel in discover - it's a link but the flyout closes on click.

@cchaos
Copy link
Contributor

cchaos commented Mar 5, 2019

So you're saying that you're providing an href as the target of the click, but that you also need to close the flyout when the link is clicked, which you want to be able to do via onClick?

Sounds to me that you need to just provide an onClick that passes the href location and then in theonClick handler, you close the flyout, then navigate to the href.

@snide
Copy link
Contributor

snide commented Mar 5, 2019

Agree with @cchaos here. href and onClick don't really mix and shouldn't be used in tandem because you can't guarantee they'll execute in any known order. More complicated actions should just use onClick and perform actions within a handler.

@flash1293
Copy link
Contributor Author

Sounds to me that you need to just provide an onClick that passes the href location and then in theonClick handler, you close the flyout, then navigate to the href.

But if I do this, I can't do "open in new tab" from this item.

@cchaos
Copy link
Contributor

cchaos commented Mar 5, 2019

You should be able to with window.open('https://...', '_blank');

@flash1293
Copy link
Contributor Author

flash1293 commented Mar 5, 2019

You should be able to with window.open('https://...', '_blank');

What I meant is that the user is able to decide whether they want to open the link in a new tab or the same tab. Either way I want to trigger some side effect (in this case closing a flyout) as a response to the navigating - in this case the navigating doesn't close the flyout even when staying in the same tab.

I think it boils down to a pro and a counter argument:

I would lean towards the pro argument since while it might not always be the cleanest way to use href and onClick together, there might be some exotic use cases which need it, but I don't hold a strong opinion about this.

@snide
Copy link
Contributor

snide commented Mar 5, 2019

We ran through this as a group today in our design meeting. We'd like to keep onClick and href distinct and follow closer to standard specs. We do this a lot in multiple components (both EuiLink and EuiButton off hand) so we'd have to address this in lots of places. The reasoning is this suggests a proper pattern that leads to consistent HTML accessibility (buttons and anchors are different) across the UI. We're a little worried about people misusing this kind of ability and mixing up their concerns. We really haven't run into this use case before, and I don't think it's going to be too common so I think it's OK to just build your own pattern outside of EUI for this.

Suggestion for now would be that if you need this kind of functionality to just use a secondary icon next to the link to suggest opening it in another tab and using a separate action. popout works for this, but we can probably make a better "link" style icon. It's just a very narrow use case. Even a second "Go here (or open in a new tab)" link next to it works if you really think this is going to be common.

image

@snide snide closed this as completed Mar 5, 2019
@stacey-gammon
Copy link
Contributor

fwiw I am hitting this need as well. I think it may be become more common because you should use onClick to navigate to internal apps without causing a full page refresh, but we also want to support "open in new tab".

Drilldown code needs this as well. Both onClick and href are set on EuiContextMenuPanelItemDescriptor, it's not hitting the ts error though for some reason. https://github.com/elastic/kibana/blob/master/src/plugins/ui_actions/public/context_menu/build_eui_context_menu_panels.tsx#L118

@stacey-gammon
Copy link
Contributor

I'm getting around it by using your pop out icon, but it feels a bit weird because most users would use right click -> open in new tab.

Screen Shot 2020-05-21 at 9 40 31 AM

@cchaos
Copy link
Contributor

cchaos commented May 21, 2020

Let's go ahead an implement allowing both onClick and href on EuiListGroupItems knowing that we have the lint message they can ignore, but at least we don't block usage or force consumers to "hack" it.

@chandlerprall
Copy link
Contributor

knowing that we have the lint message they can ignore

We'll need to update the eslint plugin to include EuiListGroupItems, and then make sure to publish that package and update it in Kibana.

const componentNames = ['EuiButton', 'EuiButtonEmpty', 'EuiLink'];

@cchaos cchaos changed the title EuiListGroupItem onClick doesn't work together with href [EuiListGroupItem] Allow onClick with href Sep 19, 2020
@github-actions
Copy link

👋 Hey there. This issue hasn't had any activity for 180 days. We'll automatically close it if that trend continues for another week. If you feel this issue is still valid and needs attention please let us know with a comment.

@flash1293
Copy link
Contributor Author

Bumping this - it’s still valid. There’s a workaround on Kibana side, but it would be nice to have it supported natively

@github-actions
Copy link

👋 Hey there. This issue hasn't had any activity for 180 days. We'll automatically close it if that trend continues for another week. If you feel this issue is still valid and needs attention please let us know with a comment.

@snide
Copy link
Contributor

snide commented Sep 15, 2021

Added a skip so the bot doesn't engage.

@cee-chen
Copy link
Member

cee-chen commented Apr 3, 2023

This appears to be have been resolved in #1933. I can't reproduce it in latest prod at least - passing both href='/' onClick={(e) => e.preventDefault() works as expected.

Edit: I also don't see a type error for passing both href and onClick, so I think that has been resolved as well.

@cee-chen cee-chen closed this as completed Apr 3, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants