You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
- Don't use a button when you want a user to navigate. Use a link instead.
32
-
- Not all color and font size combinations are available because some do not meet accessibility contrast requirements
33
-
34
31
## Considerations
35
32
36
-
### Why a webcomponent?
33
+
### Why a Web Component?
37
34
38
-
There are multiple reasons why we used a web component as opposed to a CSS component.
35
+
There are multiple reasons why we used a Web Component as opposed to a CSS component.
39
36
40
37
-**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.
41
38
-**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.
42
39
-**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.
40
+
41
+
### Event target
42
+
43
+
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.
44
+
45
+
### Flashing a native button click as a direct child of form
46
+
47
+
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.
48
+
Therefore, on click, we flash a `<button>` to the form as a direct child and fire the click on that button. We then immediately remove that button. This is a fully synchronous process; users or developers will not notice this, it should not cause problems.
49
+
50
+
### Native button & implicit form submission
51
+
52
+
Flashing the button in the way we do solves almost all issues except for one.
53
+
One of the specs of W3C is that when you have a form with multiple inputs, pressing enter while inside one of the inputs only triggers a form submit if that form has a button of type submit.
54
+
55
+
To get this particular implicit form submission to work, having a native button in our `lion-button` is a hard requirement. Therefore, not only do we flash a native button on the form to delegate `lion-button` trigger to `button` and thereby trigger form submission, we **also** add a native `button` inside the `lion-button` which `type` property is synchronized with the type of the `lion-button`.
56
+
57
+
### Preventing full page reloads
58
+
59
+
To prevent form submission full page reloads, add a **submit handler on the form** like so:
60
+
61
+
```html
62
+
<form@submit=${ev => ev.preventDefault()} >
63
+
```
64
+
65
+
Putting this on the `@click` of the `lion-button` is not enough.
0 commit comments