alphagov / govuk_frontend_toolkit

❗️GOV.UK Frontend Toolkit is deprecated, and will only receive major bug fixes and security patches.
MIT License
403 stars 107 forks source link

Fix role click shim #347

Closed NickColley closed 7 years ago

NickColley commented 8 years ago

When trying to implement the shim I found the page will scroll when pressing space, then you navigate to the page.

To fix this we need to instead listen for keydown and not keyup so we can prevent the unwanted scroll behaviour.

I've also added a commit to simplify the shim since there's not a clear need for this to be flexible.

robinwhittleton commented 7 years ago

I thought I remembered something about keydown being a bit weird in old IE, but I think I was actually thinking about keypress. I guess this has been tested in IE8+? If so I’ll merge.

NickColley commented 7 years ago

Okay after testing this again I realise keyup is the right behaviour for space.

So this PR needs to be changed to handle keydown to prevent scrolling of the page, and handle keyup to click the button...

NickColley commented 7 years ago

I can't find a place where that behaviour is defined in any spec, so I'm presuming it's down to the operating system.

I've tested this PR in IE8,IE9,IE10 and it works.

So this should be good to go as long as we can stomach the spacebar submitting on keydown and not keyup.