Sha256: 334ccd7fee4a6c5c93012e83a85ce701f2c201f5a375fb95b364c9070c08cc1e

Contents?: true

Size: 1.03 KB

Versions: 31

Compression:

Stored size: 1.03 KB

Contents

// javascript 'shim' to trigger the click event of element(s)
// when the space key is pressed.
//
// Created since some Assistive Technologies (for example some Screenreaders)
// Will tell a user to press space on a 'button', so this functionality needs to be shimmed
// See https://github.com/alphagov/govuk_elements/pull/272#issuecomment-233028270
//
// Usage instructions:
// GOVUK.shimLinksWithButtonRole.init();
;(function (global) {
  'use strict'

  var $ = global.jQuery
  var GOVUK = global.GOVUK || {}

  GOVUK.shimLinksWithButtonRole = {

    init: function init () {
      // listen to 'document' for keydown event on the any elements that should be buttons.
      $(document).on('keydown', '[role="button"]', function (event) {
        // if the keyCode (which) is 32 it's a space, let's simulate a click.
        if (event.which === 32) {
          event.preventDefault()
          // trigger the target's click event
          event.target.click()
        }
      })
    }

  }

  // hand back to global
  global.GOVUK = GOVUK
})(window)

Version data entries

31 entries across 31 versions & 2 rubygems

Version Path
govuk_frontend_toolkit-9.0.1 app/assets/javascripts/govuk/shim-links-with-button-role.js
govuk_frontend_toolkit-9.0.0 app/assets/javascripts/govuk/shim-links-with-button-role.js
govuk_frontend_toolkit-8.2.0 app/assets/javascripts/govuk/shim-links-with-button-role.js
govuk_frontend_toolkit-8.1.0 app/assets/javascripts/govuk/shim-links-with-button-role.js
govuk_frontend_toolkit-8.0.0 app/assets/javascripts/govuk/shim-links-with-button-role.js
govuk_frontend_toolkit-7.6.0 app/assets/javascripts/govuk/shim-links-with-button-role.js
idsk_frontend_toolkit-8.4.4 app/assets/javascripts/govuk/shim-links-with-button-role.js
idsk_frontend_toolkit-7.4.3 app/assets/javascripts/govuk/shim-links-with-button-role.js
govuk_frontend_toolkit-7.5.0 app/assets/javascripts/govuk/shim-links-with-button-role.js
idsk_frontend_toolkit-7.4.2 app/assets/javascripts/govuk/shim-links-with-button-role.js
govuk_frontend_toolkit-7.4.2 app/assets/javascripts/govuk/shim-links-with-button-role.js
govuk_frontend_toolkit-7.4.1 app/assets/javascripts/govuk/shim-links-with-button-role.js
govuk_frontend_toolkit-7.4.0 app/assets/javascripts/govuk/shim-links-with-button-role.js
govuk_frontend_toolkit-7.3.0 app/assets/javascripts/govuk/shim-links-with-button-role.js
govuk_frontend_toolkit-7.2.0 app/assets/javascripts/govuk/shim-links-with-button-role.js
govuk_frontend_toolkit-7.1.0 app/assets/javascripts/govuk/shim-links-with-button-role.js
govuk_frontend_toolkit-7.0.1 app/assets/javascripts/govuk/shim-links-with-button-role.js
govuk_frontend_toolkit-7.0.0 app/assets/javascripts/govuk/shim-links-with-button-role.js
govuk_frontend_toolkit-6.0.4 app/assets/javascripts/govuk/shim-links-with-button-role.js
govuk_frontend_toolkit-6.0.3 app/assets/javascripts/govuk/shim-links-with-button-role.js