-
Notifications
You must be signed in to change notification settings - Fork 324
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
Use KeyboardEvent.key
over deprecated KeyboardEvent.keyCode
in the Button component
#4812
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
📋 StatsFile sizes
Modules
View stats and visualisations on the review app Action run for 6fce6ed |
JavaScript changes to npm packagediff --git a/packages/govuk-frontend/dist/govuk/govuk-frontend.min.js b/packages/govuk-frontend/dist/govuk/govuk-frontend.min.js
index 13886ee98..b85c7040f 100644
--- a/packages/govuk-frontend/dist/govuk/govuk-frontend.min.js
+++ b/packages/govuk-frontend/dist/govuk/govuk-frontend.min.js
@@ -360,7 +360,7 @@ class Button extends GOVUKFrontendComponent {
}
handleKeyDown(t) {
const e = t.target;
- 32 === t.keyCode && e instanceof HTMLElement && "button" === e.getAttribute("role") && (t.preventDefault(), e.click())
+ " " === t.key && e instanceof HTMLElement && "button" === e.getAttribute("role") && (t.preventDefault(), e.click())
}
debounce(t) {
if (this.config.preventDoubleClick) return this.debounceFormSubmitTimer ? (t.preventDefault(), !1) : void(this.debounceFormSubmitTimer = window.setTimeout((() => {
Action run for 6fce6ed |
Other changes to npm packagediff --git a/packages/govuk-frontend/dist/govuk/all.bundle.js b/packages/govuk-frontend/dist/govuk/all.bundle.js
index 514baf6ba..51f0fc054 100644
--- a/packages/govuk-frontend/dist/govuk/all.bundle.js
+++ b/packages/govuk-frontend/dist/govuk/all.bundle.js
@@ -733,7 +733,6 @@
* 'Show' button's accessible name when a section is expanded.
*/
- const KEY_SPACE = 32;
const DEBOUNCE_TIMEOUT_IN_SECONDS = 1;
/**
@@ -765,7 +764,7 @@
}
handleKeyDown(event) {
const $target = event.target;
- if (event.keyCode !== KEY_SPACE) {
+ if (event.key !== ' ') {
return;
}
if ($target instanceof HTMLElement && $target.getAttribute('role') === 'button') {
diff --git a/packages/govuk-frontend/dist/govuk/all.bundle.mjs b/packages/govuk-frontend/dist/govuk/all.bundle.mjs
index c52909c71..4bd2f966d 100644
--- a/packages/govuk-frontend/dist/govuk/all.bundle.mjs
+++ b/packages/govuk-frontend/dist/govuk/all.bundle.mjs
@@ -727,7 +727,6 @@ const helper = {
* 'Show' button's accessible name when a section is expanded.
*/
-const KEY_SPACE = 32;
const DEBOUNCE_TIMEOUT_IN_SECONDS = 1;
/**
@@ -759,7 +758,7 @@ class Button extends GOVUKFrontendComponent {
}
handleKeyDown(event) {
const $target = event.target;
- if (event.keyCode !== KEY_SPACE) {
+ if (event.key !== ' ') {
return;
}
if ($target instanceof HTMLElement && $target.getAttribute('role') === 'button') {
diff --git a/packages/govuk-frontend/dist/govuk/components/button/button.bundle.js b/packages/govuk-frontend/dist/govuk/components/button/button.bundle.js
index 5491951c7..e8db70624 100644
--- a/packages/govuk-frontend/dist/govuk/components/button/button.bundle.js
+++ b/packages/govuk-frontend/dist/govuk/components/button/button.bundle.js
@@ -122,7 +122,6 @@
}
}
- const KEY_SPACE = 32;
const DEBOUNCE_TIMEOUT_IN_SECONDS = 1;
/**
@@ -154,7 +153,7 @@
}
handleKeyDown(event) {
const $target = event.target;
- if (event.keyCode !== KEY_SPACE) {
+ if (event.key !== ' ') {
return;
}
if ($target instanceof HTMLElement && $target.getAttribute('role') === 'button') {
diff --git a/packages/govuk-frontend/dist/govuk/components/button/button.bundle.mjs b/packages/govuk-frontend/dist/govuk/components/button/button.bundle.mjs
index c6f41e246..5e00ee6d9 100644
--- a/packages/govuk-frontend/dist/govuk/components/button/button.bundle.mjs
+++ b/packages/govuk-frontend/dist/govuk/components/button/button.bundle.mjs
@@ -116,7 +116,6 @@ class GOVUKFrontendComponent {
}
}
-const KEY_SPACE = 32;
const DEBOUNCE_TIMEOUT_IN_SECONDS = 1;
/**
@@ -148,7 +147,7 @@ class Button extends GOVUKFrontendComponent {
}
handleKeyDown(event) {
const $target = event.target;
- if (event.keyCode !== KEY_SPACE) {
+ if (event.key !== ' ') {
return;
}
if ($target instanceof HTMLElement && $target.getAttribute('role') === 'button') {
diff --git a/packages/govuk-frontend/dist/govuk/components/button/button.mjs b/packages/govuk-frontend/dist/govuk/components/button/button.mjs
index 642d4a343..541e56fab 100644
--- a/packages/govuk-frontend/dist/govuk/components/button/button.mjs
+++ b/packages/govuk-frontend/dist/govuk/components/button/button.mjs
@@ -3,7 +3,6 @@ import { normaliseDataset } from '../../common/normalise-dataset.mjs';
import { ElementError } from '../../errors/index.mjs';
import { GOVUKFrontendComponent } from '../../govuk-frontend-component.mjs';
-const KEY_SPACE = 32;
const DEBOUNCE_TIMEOUT_IN_SECONDS = 1;
/**
@@ -35,7 +34,7 @@ class Button extends GOVUKFrontendComponent {
}
handleKeyDown(event) {
const $target = event.target;
- if (event.keyCode !== KEY_SPACE) {
+ if (event.key !== ' ') {
return;
}
if ($target instanceof HTMLElement && $target.getAttribute('role') === 'button') {
Action run for 6fce6ed |
36degrees
changed the title
Use
Use Mar 1, 2024
key
over deprecated keyCode
in Buttonkey
over deprecated keyCode
in the Button component
36degrees
changed the title
Use
Use Mar 1, 2024
key
over deprecated keyCode
in the Button componentKeyboardEvent.key
over deprecated KeyboardEvent.keyCode
in the Button component
colinrotherham
approved these changes
Mar 4, 2024
`KeyboardEvent.keyCode` is deprecated. All of the browsers that now run our JavaScript support the modern `KeyboardEvent.key` property. Update the button component to using `KeyboardEvent.key` instead, removing the `KEY_SPACE` constant.
36degrees
force-pushed
the
button-keycode
branch
from
March 4, 2024 13:18
b59d72b
to
6fce6ed
Compare
Merged
This was referenced Jun 19, 2024
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
KeyboardEvent.keyCode
is deprecated. All of the browsers that now run our JavaScript support the modernKeyboardEvent.key
property.Update the button component to using
KeyboardEvent.key
instead, removing theKEY_SPACE
constant.Part of #4709