-
Notifications
You must be signed in to change notification settings - Fork 328
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
Stop links styled as button from being dragged #1020
Conversation
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.
Thank you for taking the time to write this up!
I think this makes a lot of sense, there's some stuff that needs to be done before this can be merged:
- Generate the updated READMEs (run npm start, and you should see updated README files)
- Add a CHANGELOG entry
Since these are chore tasks we're happy to do this for you, please let us know.
Edit: I think I'm going to do some cross browser testing of this for you too, just to double check this doesnt do something odd we didn't expect.
https://jsbin.com/bumulatozu/1/edit?html,css,output
- IE8: No change
- IE9: No change
- IE10: As expected
- IE11: As expected
- Edge: As expected
- Firefox: No change (but seems to work when you prevent 'ondragstart' event https://stackoverflow.com/a/30612766)
- Safari: As expected
- iOS Safari: As expected
- Chrome for Android: No change (but consistent with buttons)
283b766
to
10d3c40
Compare
@NickColley I’ve done the |
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.
LGTM, thanks @quis!
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 wonder if we'll find even more that we need to do to make links behave like buttons, thanks for getting us closer @quis :)
In user research we have seen users’ attempts at clicking links styled as buttons not registered because they moved the mouse as they were clicking. This instead triggers the browsers drag behaviour. --- One user we were observing yesterday repeatedly encountered this problem and it took several attempts before they got to the next page. I reckon this is a combination of: - having impaired motor skills - being more familiar with a trackpad and touch screen This only happens with links. With `<button>` elements you can move the mouse between depressing and releasing the button and a `click` event is still registered (as long as the cursor remains inside the button). --- Setting the `draggable` attribute to `false` prevents the drag behaviour from being triggered. This makes links styled as buttons behave in the same way as buttons. --- This attribute is supported in all current browsers: https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/draggable#Browser_compatibility It would be possible to develop this further with Javascript so a `click` event could be triggered even if the mouse left the region of the link or button before being released. This would be a more comprehensive fix, but would also involve significantly more engineering effort and potential side effects.
`role=button` for users of voice control software `draggable=false` as per alphagov/govuk-frontend#1020
`role=button` for users of voice control software `draggable=false` as per alphagov/govuk-frontend#1020
In user research we have seen users’ attempts at clicking links styled as buttons not registered because they moved the mouse as they were clicking. This instead triggers the browsers drag behaviour.
One user we were observing yesterday repeatedly encountered this problem and it took several attempts before they got to the next page. I reckon this is a combination of:
This only happens with links. With
<button>
elements you can move the mouse between depressing and releasing the button and aclick
event is still registered (as long as the cursor remains inside the button).Setting the
draggable
attribute1 tofalse
prevents the drag behaviour from being triggered. This makes links styled as buttons behave in the same way as buttons2.draggable
is supported in all current browsers: https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/draggable#Browser_compatibilityButtons still have the problem of not registering a click if you drag outside the button’s area before releasing the mouse. It would be possible to use Javascript to trigger a
click
event even if the mouse left the region of the link or button before being released. This would be a more comprehensive fix, but would also involve significantly more engineering effort and potential side effects.