From 1085a6de4ecfb6a59d574025f177dc4dc1394195 Mon Sep 17 00:00:00 2001 From: u7146335 Date: Sun, 20 Oct 2024 01:57:46 +1100 Subject: [PATCH 1/2] Implemented fix and added testing code --- src/components/button/Primary.vue | 14 ++++++-- src/stories/Button.story.vue | 59 +++++++++++++++++++++++++++++-- 2 files changed, 69 insertions(+), 4 deletions(-) diff --git a/src/components/button/Primary.vue b/src/components/button/Primary.vue index 7ca3b98..dcb6604 100644 --- a/src/components/button/Primary.vue +++ b/src/components/button/Primary.vue @@ -26,6 +26,7 @@ :disabled="disabled" :tabindex="loading ? '-1' : '0'" role="button" + @keydown="handleKeypress" > (), { +const props = withDefaults(defineProps(), { to: "", exact: true, blank: false, @@ -103,4 +104,13 @@ withDefaults(defineProps(), { outline: false, shortcut: () => [], }) - + +const handleKeypress = (event: KeyboardEvent) => { + // Check if the button is in a loading state + if (props.loading && (event.key === "Enter" || event.key === " ")){ + event.preventDefault(); // Prevent keypresses when loading + } else { + console.log('Enter succeeds as normal') + } +}; + \ No newline at end of file diff --git a/src/stories/Button.story.vue b/src/stories/Button.story.vue index e1dbead..5410fce 100644 --- a/src/stories/Button.story.vue +++ b/src/stories/Button.story.vue @@ -1,14 +1,69 @@ From 3fc0759e84d6414a1060170f6f4b43c75136b495 Mon Sep 17 00:00:00 2001 From: u7146335 Date: Sun, 20 Oct 2024 14:46:48 +1100 Subject: [PATCH 2/2] Seperated story and restored original --- src/components/button/Primary.vue | 4 +- src/stories/Button.story.vue | 61 ++------------------------- src/stories/Keypress.story.vue | 70 +++++++++++++++++++++++++++++++ 3 files changed, 74 insertions(+), 61 deletions(-) create mode 100644 src/stories/Keypress.story.vue diff --git a/src/components/button/Primary.vue b/src/components/button/Primary.vue index dcb6604..40f7bc0 100644 --- a/src/components/button/Primary.vue +++ b/src/components/button/Primary.vue @@ -108,9 +108,7 @@ const props = withDefaults(defineProps(), { const handleKeypress = (event: KeyboardEvent) => { // Check if the button is in a loading state if (props.loading && (event.key === "Enter" || event.key === " ")){ - event.preventDefault(); // Prevent keypresses when loading - } else { - console.log('Enter succeeds as normal') + event.preventDefault(); } }; \ No newline at end of file diff --git a/src/stories/Button.story.vue b/src/stories/Button.story.vue index 5410fce..c51e354 100644 --- a/src/stories/Button.story.vue +++ b/src/stories/Button.story.vue @@ -1,69 +1,14 @@ + \ No newline at end of file diff --git a/src/stories/Keypress.story.vue b/src/stories/Keypress.story.vue new file mode 100644 index 0000000..b56c674 --- /dev/null +++ b/src/stories/Keypress.story.vue @@ -0,0 +1,70 @@ + + + + \ No newline at end of file