From d19ca7cc5c7e41c9b4ac6170540ad43a9e7face2 Mon Sep 17 00:00:00 2001 From: qa46hx Date: Tue, 15 Oct 2019 13:24:08 +0200 Subject: [PATCH 1/2] fix(button): fix form integration, fires only once, submit preventable Co-authored-by: Joren Broekema --- packages/button/README.md | 33 ++++- packages/button/src/LionButton.js | 53 ++++--- packages/button/stories/index.stories.js | 58 ++++++-- packages/button/test/lion-button.test.js | 170 +++++++++++++++-------- 4 files changed, 226 insertions(+), 88 deletions(-) diff --git a/packages/button/README.md b/packages/button/README.md index a19ca1bf9..81bac11c2 100644 --- a/packages/button/README.md +++ b/packages/button/README.md @@ -28,15 +28,38 @@ import '@lion/button/lion-button.js'; Button Text ``` -- Don't use a button when you want a user to navigate. Use a link instead. -- Not all color and font size combinations are available because some do not meet accessibility contrast requirements - ## Considerations -### Why a webcomponent? +### Why a Web Component? -There are multiple reasons why we used a web component as opposed to a CSS component. +There are multiple reasons why we used a Web Component as opposed to a CSS component. - **Target size**: The minimum target size is 40 pixels, which makes even the small buttons easy to activate. A container element was needed to make this size possible. - **Accessibility**: Our button is accessible because it uses the native button element. Having this native button element available in the light dom, preserves all platform accessibility features, like having it recognized by a native form. - **Advanced styling**: There are advanced styling options regarding icons in buttons, where it is a lot more maintainable to handle icons in our button using slots. An example is that a sticky icon-only buttons may looks different from buttons which have both icons and text. + +### Event target + +We want to ensure that the event target returned to the user is `lion-button`, not `button`. Therefore, simply delegating the click to the native button immediately, is not desired. Instead, we catch the click event in the `lion-button`, and ensure delegation inside of there. + +### Flashing a native button click as a direct child of form + +By delegating the `click()` to the native button, it will bubble back up to `lion-button` which would cause duplicate actions. We have to simulate the full `.click()` however, otherwise form submission is not triggered. So this bubbling cannot be prevented. +Therefore, on click, we flash a `