-
Notifications
You must be signed in to change notification settings - Fork 109
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
Ctrl + Click on card doesn't open new tab #749
Comments
This issue is caused by the fact that clickable cards use javascript to |
Something like checking if the ctrl key is used may work (not tested): card.addEventListener('click', (event) => {
if (event.ctrlKey) {
window.open(card.querySelector('a').getAttribute('href'));
} else {
card.querySelector('a').click();
}
}); Although that doesn't factor in if the click is set up to do something else (highlighting target elements container fieldset/group for example). It may not work as expected on other platforms (e.g. MacOS). |
I think the root issue here is that we're faking a link when it's not semantically defined in the HTML. |
I think it may make sense to use the .nhsuk-card--clickable {
&:hover,
&:active {
cursor: auto;
}
}
.js-enabled .nhsuk-card--clickable {
&:hover,
&:active {
cursor: pointer;
}
} |
It could be done without JS at all by positioning a pseudo element from inside the tag over the top of the whole card. So when you click on the card, you are clicking the underlying link element like this: https://codepen.io/andymantell/pen/XWjXWzK Pro: No JS needed - and all "normal" ways of clicking a link just work (i.e. Ctrl-Click, Middle click, Right click and select "open in new tab") Interestingly, the current JS implementation already prevents users selecting the text because as soon as you mouseup on the card, it navigates away from the current page, even though I was trying to select the text, not click it! |
The JS loading styling issue could be resolved just by modifying how the styles are applied. Which probably should be done anyway. |
Nomensa have a good blog post around clickable cards, different ways to do them and use them https://www.nomensa.com/blog/how-build-accessible-cards-block-links @mikemonteith Users can still Ctrl + Click onto the link/title itself, as that still respects standard link behaviour. |
@Fenwick17 Ctrl+click on the link/title itself causes a new tab and navigates the current tab. (Firefox) And anyway users shouldn't have to know where on the card they should click or not click if the entire thing is clickable |
I should be able to do some further testing on this and the example @andymantell provided next week. Adrien Roselli also has a good blog post regarding the CSS only implementation https://adrianroselli.com/2020/02/block-links-cards-clickable-regions-etc.html |
I have done some testing on this with the CSS only solution, and a modified version of the current JS solution: CSS Only
JS solution
|
the JS solution would still not work when using a middle mouse button? And on windows, e.metaKey is the windows button, but it is the Ctrl button which is used to open new tabs. |
As for the CSS solution, with the following html:
|
Generally I would be in favour of moving to the CSS only solution. The only real downside is the no text selection, which is semi possible with the JS implementation if you copy before mouseup. |
Potentially related issue: #758 |
Bug Report
Ctrl + Click not respected on card components
What is the issue?
When ctrl + clicking on the body of a clickable card, the link navigates insside the current tab.
It is expected that ctrl + click creates a new tab in most browsers.
What steps are required to reproduce the issue?
Ctrl + Click on a card. (examples here https://www.nhs.uk/pregnancy/)
N.B ctrl + click on the title of the card opens a new tab and navigates the current tab.
The text was updated successfully, but these errors were encountered: