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

Feature/anchor buttons #297

Merged
merged 3 commits into from
Aug 10, 2016
Merged

Feature/anchor buttons #297

merged 3 commits into from
Aug 10, 2016

Conversation

paulmsmith
Copy link
Contributor

As discussed in 'remove button role from start link' here is a pull request to shim anchors with role="button" to be 'clicked' via the space key.

I've not written tests yet, assuming the general style of this is fine then I'll do that. My thoughts were that this shim should be configurable but I've heard opinion that for a 'shim' that is not always a good thing. Thoughts, Suggestions welcome. :)


};

// if disbaleInit is not true then run the init method
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typo ;)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good spot! Will fix.

@NickColley
Copy link
Contributor

Thanks a lot for getting this together Paul 👍

One thing that worries me with this is it could break the behaviour of scrolling the page when pressing space.

It seems as though if a user is focused on a link it's okay to block that behaviour but I'm not entirely sure of all the edge cases so thought I'd comment in the hope that someone else can think about this too.

triggerClickOnTarget: function triggerClickOnTarget(event) {
var code = event.charCode || event.keyCode;
// if the keyCode/charCode from this event is in the keycodes array then
if ($.inArray(code, this.config.keycodes) !== -1) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A nit (sorry) but I'm wondering, if we're only ever going to be shimming the spacekey, could we just do a boring

code === 32

here instead of an array comparison, not super important (sorry again :P)

Copy link
Contributor Author

@paulmsmith paulmsmith Jul 27, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Again fair point. Originally there was talk of triggering on enter/return as well. Left it open to additional key-codes just in case more than anything. Happy to change if we feel that makes it more readable/explicit.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Generally for me I prefer to avoid anticipating future updates since more often than not they don't happen but don't think this blocks merging, so up to you. ✌️

@robinwhittleton
Copy link
Contributor

This adds a file, but won’t roll it out across GOV.UK. I guess we want to add it to govuk_template.js, intialise it in govuk_template’s core.js, then push a new version and update static’s Gemfile to use that.

@paulmsmith
Copy link
Contributor Author

Hi all, I've made the updates after the suggestions. I have changed it now so that the event listener is on the document and I have also updated the module pattern so that it needs to be explicitly initiated.

@paulmsmith paulmsmith changed the title WIP: Feature/anchor buttons Feature/anchor buttons Jul 29, 2016
@paulmsmith
Copy link
Contributor Author

@robinwhittleton I'm due to go away for two weeks now. I've removed the 'WIP' from the title and I think this can be merged whenever you and others feel is a good time.

@gemmaleigh
Copy link
Contributor

@paulmsmith thanks for this! We'll review shortly. Have a good break!

@gemmaleigh
Copy link
Contributor

I'd like to get @aduggin's opinion on this before we merge.

},

// By default this will find all anchors with role attribute set to
// 'button' and will trigger their click event when the spaceky (32) is pressed.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mini-nit, typo in comment (spacekey)

@aduggin
Copy link

aduggin commented Aug 10, 2016

This approach looks good to me

@robinwhittleton
Copy link
Contributor

Thanks. Will merge this now, address @gemmaleigh’s nits in a further PR.

@robinwhittleton robinwhittleton merged commit 8e403dd into alphagov:master Aug 10, 2016
robinwhittleton pushed a commit that referenced this pull request Aug 11, 2016
- Add support for Google Analytics fieldsObject (PR #298)
- anchor-buttons.js: normalise keyboard behaviour between buttons and links with a button role (PR #297)
gemmaleigh added a commit to alphagov/govuk_accessibility_sandbox that referenced this pull request Sep 6, 2016
https://github.com/alphagov/govuk_frontend_toolkit/blob/master/CHANGELOG
.md

# 4.18.0

- Add GOVUK.ShowHideContent JavaScript to support showing and hiding
content, toggled by radio buttons and checkboxes ([PR
#315](alphagov/govuk_frontend_toolkit#315)).

# 4.17.0

- SelectionButtons will add a class to the label with the type of the
child input ([PR
#317](alphagov/govuk_frontend_toolkit#317))

# 4.16.1

- Fix anchor-buttons.js to trigger a native click event, also rename to
shimLinksWithButtonRole.js to explain what it does
- Add tests for shimLinksWithButtonRole ([PR
#310](alphagov/govuk_frontend_toolkit#310))

# 4.16.0

- Add Department for International Trade organisation ([PR
#308](alphagov/govuk_frontend_toolkit#308))

# 4.15.0

- Add support for Google Analytics fieldsObject ([PR
#298](alphagov/govuk_frontend_toolkit#298))
- anchor-buttons.js: normalise keyboard behaviour between buttons and
links with a button role ([PR
#297](alphagov/govuk_frontend_toolkit#297))

# 4.14.1

- Fix tabular number sizing in Firefox ([PR
#301](alphagov/govuk_frontend_toolkit#301))

# 4.14.0

- Allow use of multiple GA customDimensionIndex. See [this
section](https://github.com/alphagov/govuk_frontend_toolkit/blob/master/
docs/javascript.md#using-google-custom-dimensions-with-your-own-statisti
cal-model) of the documentation for more information.
- Configurable duration (in days) for AB Test cookie. See [this
section](https://github.com/alphagov/govuk_frontend_toolkit/blob/master/
docs/javascript.md#multivariate-test-framework) of the documentation
for more information.
- Allow base scripts to run within a module loader. See [this
PR](alphagov/govuk_frontend_toolkit#290) for
more information.

# 4.13.0

- Make headings block-level by default (PR #200). If you are styling
elements you want to be inline with heading includes, you’ll need to
explicitly make them inline in your CSS.

# 4.12.0

- Increase button padding to match padding from GOV.UK elements (PR
#275).
If you have UI which depends on the padding set by the button mixin in
the frontend toolkit and this is not overridden by button padding set
by GOV.UK elements, this change will affect it.

# 4.11.0

- Remove the GDS-Logo font-face definition (PR #272)
- Move the @Viewport statements to govuk_template (PR #272). If you
upgrade to this version of govuk_frontend_toolkit and you’re also using
govuk_template you’ll need to upgrade that to at least 0.17.2 to
maintain compatibility with desktop IE10 in snap mode.

# 4.10.0

- Allow New Transport font stack to be overridden by apps using
`$toolkit-font-stack`
and `$toolkit-font-stack-tabular` (PR #230)

# 4.9.1

- Fix phase banner alignment (PR #266)

# 4.9.0

- Add websafe organisation colours
- Split colours into two files with backwards-compatible colours.scss
replacement

# 4.8.2

- Add GOV.UK lint to lint scss files (PR #260)
- Remove reference to old colour palette (PR #256)
- Fix link to GOV.UK elements - tabular data

# 4.8.1

- Update DEFRA brand colour to new green (PR #249)

# 4.8.0

- Pass cohort name to analytics when using multivariate test (PR #251)

# 4.7.0

- Add 'mailto' tracking to GOV.UK Analytics (PR #244)

# 4.6.1

- Use the Sass variable $light-blue for link active and hover colours
(PR #242)
gemmaleigh added a commit to alphagov/service-manual-frontend that referenced this pull request Oct 7, 2016
https://github.com/alphagov/govuk_frontend_toolkit/blob/master/CHANGELOG
.md

# 4.18.3

- For smaller screens (<768px) ensure that the
GOVUK.StickAtTopWhenScrolling JS "unsticks" the element which was
previously "stuck" (by removing both the class which sets fixed
positioning and the shim). ([PR
#329](alphagov/govuk_frontend_toolkit#329))

# 4.18.2

- Remove unnecessary print font fallback that causes regression
downstream ([PR
#328](alphagov/govuk_frontend_toolkit#328))
- Update tooling to use npm script rather than grunt-shell ([PR
#327](alphagov/govuk_frontend_toolkit#327))

# 4.18.1

- Fix error in IE - remove trailing comma from shimLinksWithButtonRole
JavaScript ([PR
#323](alphagov/govuk_frontend_toolkit#323)).

# 4.18.0

- Add GOVUK.ShowHideContent JavaScript to support showing and hiding
content, toggled by radio buttons and checkboxes ([PR
#315](alphagov/govuk_frontend_toolkit#315)).

# 4.17.0

- SelectionButtons will add a class to the label with the type of the
child input ([PR
#317](alphagov/govuk_frontend_toolkit#317))

# 4.16.1

- Fix anchor-buttons.js to trigger a native click event, also rename to
shimLinksWithButtonRole.js to explain what it does
- Add tests for shimLinksWithButtonRole ([PR
#310](alphagov/govuk_frontend_toolkit#310))

# 4.16.0

- Add Department for International Trade organisation ([PR
#308](alphagov/govuk_frontend_toolkit#308))

# 4.15.0

- Add support for Google Analytics fieldsObject ([PR
#298](alphagov/govuk_frontend_toolkit#298))
- anchor-buttons.js: normalise keyboard behaviour between buttons and
links with a button role ([PR
#297](alphagov/govuk_frontend_toolkit#297))

# 4.14.1

- Fix tabular number sizing in Firefox ([PR
#301](alphagov/govuk_frontend_toolkit#301))

# 4.14.0

- Allow use of multiple GA customDimensionIndex. See [this
section](https://github.com/alphagov/govuk_frontend_toolkit/blob/master/
docs/javascript.md#using-google-custom-dimensions-with-your-own-statisti
cal-model) of the documentation for more information.
- Configurable duration (in days) for AB Test cookie. See [this
section](https://github.com/alphagov/govuk_frontend_toolkit/blob/master/
docs/javascript.md#multivariate-test-framework) of the documentation
for more information.
- Allow base scripts to run within a module loader. See [this
PR](alphagov/govuk_frontend_toolkit#290) for
more information.

# 4.13.0

- Make headings block-level by default (PR #200). If you are styling
elements you want to be inline with heading includes, you’ll need to
explicitly make them inline in your CSS.

# 4.12.0

- Increase button padding to match padding from GOV.UK elements (PR
#275).
If you have UI which depends on the padding set by the button mixin in
the frontend toolkit and this is not overridden by button padding set
by GOV.UK elements, this change will affect it.

# 4.11.0

- Remove the GDS-Logo font-face definition (PR #272)
- Move the @Viewport statements to govuk_template (PR #272). If you
upgrade to this version of govuk_frontend_toolkit and you’re also using
govuk_template you’ll need to upgrade that to at least 0.17.2 to
maintain compatibility with desktop IE10 in snap mode.
gemmaleigh added a commit to alphagov/service-manual-frontend that referenced this pull request Oct 8, 2016
https://github.com/alphagov/govuk_frontend_toolkit/blob/master/CHANGELOG
.md

4.18.3

- For smaller screens (<768px) ensure that the
GOVUK.StickAtTopWhenScrolling JS "unsticks" the element which was
previously "stuck" (by removing both the class which sets fixed
positioning and the shim). ([PR 329](alphagov/govuk_frontend_toolkit#329))

4.18.2

- Remove unnecessary print font fallback that causes regression
downstream ([PR 328](alphagov/govuk_frontend_toolkit#328))
- Update tooling to use npm script rather than grunt-shell ([PR 327](alphagov/govuk_frontend_toolkit#327))

4.18.1

- Fix error in IE - remove trailing comma from shimLinksWithButtonRole
JavaScript ([PR 323](alphagov/govuk_frontend_toolkit#323)).

4.18.0

- Add GOVUK.ShowHideContent JavaScript to support showing and hiding
content, toggled by radio buttons and checkboxes ([PR 315](alphagov/govuk_frontend_toolkit#315)).

4.17.0

- SelectionButtons will add a class to the label with the type of the
child input ([PR 317](alphagov/govuk_frontend_toolkit#317))

4.16.1

- Fix anchor-buttons.js to trigger a native click event, also rename to
shimLinksWithButtonRole.js to explain what it does
- Add tests for shimLinksWithButtonRole ([PR 310](alphagov/govuk_frontend_toolkit#310))

4.16.0

- Add Department for International Trade organisation ([PR 308](alphagov/govuk_frontend_toolkit#308))

4.15.0

- Add support for Google Analytics fieldsObject ([PR 298](alphagov/govuk_frontend_toolkit#298))
- anchor-buttons.js: normalise keyboard behaviour between buttons and
links with a button role ([PR 297](alphagov/govuk_frontend_toolkit#297))

4.14.1

- Fix tabular number sizing in Firefox ([PR 301](alphagov/govuk_frontend_toolkit#301))

4.14.0

- Allow use of multiple GA customDimensionIndex. See [this
section](https://github.com/alphagov/govuk_frontend_toolkit/blob/master/
docs/javascript.md#using-google-custom-dimensions-with-your-own-statisti
cal-model) of the documentation for more information.
- Configurable duration (in days) for AB Test cookie. See [this
section](https://github.com/alphagov/govuk_frontend_toolkit/blob/master/
docs/javascript.md#multivariate-test-framework) of the documentation
for more information.
- Allow base scripts to run within a module loader. See [this
PR](alphagov/govuk_frontend_toolkit#290) for
more information.

4.13.0

- Make headings block-level by default (PR #200). If you are styling
elements you want to be inline with heading includes, you’ll need to
explicitly make them inline in your CSS.

4.12.0

- Increase button padding to match padding from GOV.UK elements (PR 275).
If you have UI which depends on the padding set by the button mixin in
the frontend toolkit and this is not overridden by button padding set
by GOV.UK elements, this change will affect it.

4.11.0

- Remove the GDS-Logo font-face definition (PR #272)
- Move the @Viewport statements to govuk_template (PR #272). If you
upgrade to this version of govuk_frontend_toolkit and you’re also using
govuk_template you’ll need to upgrade that to at least 0.17.2 to
maintain compatibility with desktop IE10 in snap mode.
gemmaleigh added a commit to alphagov/service-manual-frontend that referenced this pull request Oct 8, 2016
https://github.com/alphagov/govuk_frontend_toolkit/blob/master/CHANGELOG
.md

4.18.3

- For smaller screens (<768px) ensure that the
GOVUK.StickAtTopWhenScrolling JS "unsticks" the element which was
previously "stuck" (by removing both the class which sets fixed
positioning and the shim). ([PR 329](alphagov/govuk_frontend_toolkit#329))

4.18.2

- Remove unnecessary print font fallback that causes regression
downstream ([PR 328](alphagov/govuk_frontend_toolkit#328))
- Update tooling to use npm script rather than grunt-shell ([PR 327](alphagov/govuk_frontend_toolkit#327))

4.18.1

- Fix error in IE - remove trailing comma from shimLinksWithButtonRole
JavaScript ([PR 323](alphagov/govuk_frontend_toolkit#323)).

4.18.0

- Add GOVUK.ShowHideContent JavaScript to support showing and hiding
content, toggled by radio buttons and checkboxes ([PR 315](alphagov/govuk_frontend_toolkit#315)).

4.17.0

- SelectionButtons will add a class to the label with the type of the
child input ([PR 317](alphagov/govuk_frontend_toolkit#317))

4.16.1

- Fix anchor-buttons.js to trigger a native click event, also rename to
shimLinksWithButtonRole.js to explain what it does
- Add tests for shimLinksWithButtonRole ([PR 310](alphagov/govuk_frontend_toolkit#310))

4.16.0

- Add Department for International Trade organisation ([PR 308](alphagov/govuk_frontend_toolkit#308))

4.15.0

- Add support for Google Analytics fieldsObject ([PR 298](alphagov/govuk_frontend_toolkit#298))
- anchor-buttons.js: normalise keyboard behaviour between buttons and
links with a button role ([PR 297](alphagov/govuk_frontend_toolkit#297))

4.14.1

- Fix tabular number sizing in Firefox ([PR 301](alphagov/govuk_frontend_toolkit#301))

4.14.0

- Allow use of multiple GA customDimensionIndex. See [this
section](https://github.com/alphagov/govuk_frontend_toolkit/blob/master/
docs/javascript.md#using-google-custom-dimensions-with-your-own-statisti
cal-model) of the documentation for more information.
- Configurable duration (in days) for AB Test cookie. See [this
section](https://github.com/alphagov/govuk_frontend_toolkit/blob/master/
docs/javascript.md#multivariate-test-framework) of the documentation
for more information.
- Allow base scripts to run within a module loader. See [this
PR](alphagov/govuk_frontend_toolkit#290) for
more information.

4.13.0

- Make headings block-level by default (PR #200). If you are styling
elements you want to be inline with heading includes, you’ll need to
explicitly make them inline in your CSS.

4.12.0

- Increase button padding to match padding from GOV.UK elements (PR 275).
If you have UI which depends on the padding set by the button mixin in
the frontend toolkit and this is not overridden by button padding set
by GOV.UK elements, this change will affect it.

4.11.0

- Remove the GDS-Logo font-face definition (PR #272)
- Move the @Viewport statements to govuk_template (PR #272). If you
upgrade to this version of govuk_frontend_toolkit and you’re also using
govuk_template you’ll need to upgrade that to at least 0.17.2 to
maintain compatibility with desktop IE10 in snap mode.
pcraig3 added a commit to Crown-Commercial-Service/digitalmarketplace-frontend-toolkit that referenced this pull request Feb 15, 2017
Another of the changes pulled in in the latest
template is that links with a role="button" can be targeted
by a script that will treat them the same as buttons.
This means you can press the space bar when they're focused
and it should register a click.

Frontend apps will have to set up their javascript independently,
but the button role will be in the markup from now on.

Source: alphagov/govuk_frontend_toolkit#297
pcraig3 added a commit to Crown-Commercial-Service/digitalmarketplace-frontend-toolkit that referenced this pull request Feb 15, 2017
Another of the changes pulled in in the latest
template is that links with a role="button" can be targeted
by a script that will treat them the same as buttons.
This means you can press the space bar when they're focused
and it should register a click.

Frontend apps will have to set up their javascript independently,
but the button role will be in the markup from now on.

Source: alphagov/govuk_frontend_toolkit#297
pcraig3 added a commit to Crown-Commercial-Service/digitalmarketplace-frontend-toolkit that referenced this pull request Feb 15, 2017
Another of the changes pulled in in the latest
template is that links with a role="button" can be targeted
by a script that will treat them the same as buttons.
This means you can press the space bar when they're focused
and it should register a click.

Frontend apps will have to set up their javascript independently,
but the button role will be in the markup from now on.

Source: alphagov/govuk_frontend_toolkit#297
pcraig3 added a commit to Crown-Commercial-Service/digitalmarketplace-frontend-toolkit that referenced this pull request Feb 15, 2017
Another of the changes pulled in in the latest
template is that links with a role="button" can be targeted
by a script that will treat them the same as buttons.
This means you can press the space bar when they're focused
and it should register a click.

Frontend apps will have to set up their javascript independently,
but the button role will be in the markup from now on.

Source: alphagov/govuk_frontend_toolkit#297
pcraig3 added a commit to Crown-Commercial-Service/digitalmarketplace-frontend-toolkit that referenced this pull request Feb 16, 2017
Another of the changes pulled in in the latest
template is that links with a role="button" can be targeted
by a script that will treat them the same as buttons.
This means you can press the space bar when they're focused
and it should register a click.

Frontend apps will have to set up their javascript independently,
but the button role will be in the markup from now on.

Source: alphagov/govuk_frontend_toolkit#297
pcraig3 added a commit to Crown-Commercial-Service/digitalmarketplace-frontend-toolkit that referenced this pull request Feb 16, 2017
Another of the changes pulled in in the latest
template is that links with a role="button" can be targeted
by a script that will treat them the same as buttons.
This means you can press the space bar when they're focused
and it should register a click.

Frontend apps will have to set up their javascript independently,
but the button role will be in the markup from now on.

Source: alphagov/govuk_frontend_toolkit#297
pcraig3 added a commit to Crown-Commercial-Service/digitalmarketplace-frontend-toolkit that referenced this pull request Feb 16, 2017
Another of the changes pulled in in the latest
template is that links with a role="button" can be targeted
by a script that will treat them the same as buttons.
This means you can press the space bar when they're focused
and it should register a click.

Frontend apps will have to set up their javascript independently,
but the button role will be in the markup from now on.

Source: alphagov/govuk_frontend_toolkit#297
pcraig3 added a commit to Crown-Commercial-Service/digitalmarketplace-frontend-toolkit that referenced this pull request Feb 22, 2017
Another of the changes pulled in in the latest
template is that links with a role="button" can be targeted
by a script that will treat them the same as buttons.
This means you can press the space bar when they're focused
and it should register a click.

Frontend apps will have to set up their javascript independently,
but the button role will be in the markup from now on.

Source: alphagov/govuk_frontend_toolkit#297
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants