@lion/ui 0.15.5 → 0.16.0-alpha.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/components/overlays/src/OverlayController.js +99 -66
- package/components/overlays/src/OverlaysManager.js +0 -33
- package/components/overlays/test/OverlayController.test.js +52 -30
- package/custom-elements.json +105 -200
- package/dist-types/components/overlays/src/OverlayController.d.ts +1 -11
- package/dist-types/components/overlays/src/OverlayController.d.ts.map +1 -1
- package/dist-types/components/overlays/src/OverlaysManager.d.ts +0 -12
- package/dist-types/components/overlays/src/OverlaysManager.d.ts.map +1 -1
- package/dist-types/components/overlays/test/OverlayController.test.d.ts.map +1 -1
- package/dist-types/exports/overlays.d.ts +0 -1
- package/dist-types/tsconfig.tsbuildinfo +1 -1
- package/docs/components/checkbox-group/overview.md +2 -2
- package/docs/components/collapsible/overview.md +1 -1
- package/docs/components/combobox/overview.md +1 -1
- package/docs/components/combobox/use-cases.md +1 -1
- package/docs/components/dialog/overview.md +1 -1
- package/docs/components/fieldset/overview.md +5 -5
- package/docs/components/form/overview.md +3 -3
- package/docs/components/form/use-cases.md +2 -2
- package/docs/components/icon/use-cases.md +1 -1
- package/docs/components/input/overview.md +1 -1
- package/docs/components/input-amount/overview.md +3 -3
- package/docs/components/input-date/overview.md +3 -3
- package/docs/components/input-datepicker/overview.md +5 -5
- package/docs/components/input-email/overview.md +2 -2
- package/docs/components/input-file/overview.md +1 -1
- package/docs/components/input-iban/overview.md +2 -2
- package/docs/components/input-range/overview.md +2 -2
- package/docs/components/input-stepper/overview.md +1 -1
- package/docs/components/input-tel/overview.md +1 -1
- package/docs/components/input-tel/use-cases.md +6 -6
- package/docs/components/input-tel-dropdown/overview.md +1 -1
- package/docs/components/listbox/use-cases.md +1 -1
- package/docs/components/radio-group/overview.md +3 -3
- package/docs/components/select/use-cases.md +1 -1
- package/docs/components/select-rich/use-cases.md +2 -2
- package/docs/components/tabs/examples.md +1 -1
- package/docs/fundamentals/index.md +4 -4
- package/docs/fundamentals/node-tools/publish-docs/overview.md +3 -3
- package/docs/fundamentals/node-tools/rocket-preset-extend-lion-docs/overview.md +2 -2
- package/docs/fundamentals/rationales/accessibility.md +1 -1
- package/docs/fundamentals/systems/core/SlotMixin.md +1 -1
- package/docs/fundamentals/systems/core/overview.md +1 -1
- package/docs/fundamentals/systems/form/formatting-and-parsing.md +4 -4
- package/docs/fundamentals/systems/form/model-value.md +1 -1
- package/docs/fundamentals/systems/form/overview.md +28 -28
- package/docs/fundamentals/systems/form/validate.md +2 -2
- package/docs/fundamentals/systems/localize/overview.md +4 -4
- package/docs/fundamentals/systems/overlays/api-table.md +45 -51
- package/docs/fundamentals/systems/overlays/configuration.md +5 -2
- package/docs/fundamentals/systems/overlays/overview.md +5 -5
- package/docs/fundamentals/systems/overlays/use-cases.md +2 -2
- package/docs/fundamentals/tools/helpers/overview.md +1 -1
- package/docs/fundamentals/tools/singleton-manager/overview.md +4 -4
- package/docs/guides/how-to/create-a-custom-field.md +5 -5
- package/docs/guides/how-to/create-a-form.md +4 -4
- package/docs/guides/how-to/extend-a-native-input.md +2 -2
- package/docs/guides/index.md +8 -8
- package/docs/guides/principles/index.md +5 -5
- package/docs/guides/principles/styling.md +1 -1
- package/exports/overlays.js +0 -1
- package/overlays.js +0 -1
- package/package.json +1 -1
- package/components/overlays/src/utils/contain-focus.js +0 -202
- package/components/overlays/test/utils-tests/contain-focus.test.js +0 -236
- package/dist-types/components/overlays/src/utils/contain-focus.d.ts +0 -20
- package/dist-types/components/overlays/src/utils/contain-focus.d.ts.map +0 -1
- package/dist-types/components/overlays/test/utils-tests/contain-focus.test.d.ts +0 -2
- package/dist-types/components/overlays/test/utils-tests/contain-focus.test.d.ts.map +0 -1
|
@@ -34,7 +34,7 @@ The overlay system allows to create different types of overlays like dialogs, to
|
|
|
34
34
|
It's designed to be highly flexible, while still delivering sensible defaults.
|
|
35
35
|
On top of this, the system was built having accessibility in mind.
|
|
36
36
|
|
|
37
|
-
For a detailed rationale, please consult [Rationale](https://github.com/ing-bank/lion/blob/
|
|
37
|
+
For a detailed rationale, please consult [Rationale](https://github.com/ing-bank/lion/blob/cd21c9386e7a9818a71d3e12d7b46c32b7fe76ff/docs/fundamentals/systems/overlays/rationale.md).
|
|
38
38
|
|
|
39
39
|
```js preview-story
|
|
40
40
|
export const main = () => html`
|
|
@@ -82,7 +82,7 @@ Global refers to overlays where the content is positioned in a global root node
|
|
|
82
82
|
|
|
83
83
|
Overlays can be configured in many ways to suit your needs. We go in-depth into each option in the Overlay System - Configuration chapter.
|
|
84
84
|
|
|
85
|
-
We also export a few [preset configuration objects](https://github.com/ing-bank/lion/blob/
|
|
85
|
+
We also export a few [preset configuration objects](https://github.com/ing-bank/lion/blob/cd21c9386e7a9818a71d3e12d7b46c32b7fe76ff/docs/fundamentals/systems/overlays/configuration.md).
|
|
86
86
|
|
|
87
87
|
- withModalDialogConfig
|
|
88
88
|
- withDropdownConfig
|
|
@@ -22,7 +22,7 @@ Therefore, they may not have the same quality standards as our other packages.
|
|
|
22
22
|
|
|
23
23
|
| Package | Description |
|
|
24
24
|
| -------------------------------------- | ----------------------- |
|
|
25
|
-
| [sb-action-logger](https://github.com/ing-bank/lion/blob/
|
|
25
|
+
| [sb-action-logger](https://github.com/ing-bank/lion/blob/cd21c9386e7a9818a71d3e12d7b46c32b7fe76ff/docs/fundamentals/tools/helpers/action-logger.md) | Storybook action logger |
|
|
26
26
|
|
|
27
27
|
## Installation
|
|
28
28
|
|
|
@@ -22,7 +22,7 @@ Primarily useful if two major version of a package with a singleton is used.
|
|
|
22
22
|
npm i --save singleton-manager
|
|
23
23
|
```
|
|
24
24
|
|
|
25
|
-
⚠️ You need to make SURE that only ONE version of `singleton-manager` is installed. For how see [Non Goals](https://github.com/ing-bank/lion/blob/
|
|
25
|
+
⚠️ You need to make SURE that only ONE version of `singleton-manager` is installed. For how see [Non Goals](https://github.com/ing-bank/lion/blob/cd21c9386e7a9818a71d3e12d7b46c32b7fe76ff/docs/fundamentals/tools/singleton-manager/#non-goals).
|
|
26
26
|
|
|
27
27
|
### Example Singleton Users
|
|
28
28
|
|
|
@@ -172,7 +172,7 @@ Steps to reproduce:
|
|
|
172
172
|
1. Page A click on block
|
|
173
173
|
2. Page B => "Blocked: false" (even when hitting the refresh button)
|
|
174
174
|
|
|
175
|
-
➡️ See [it on the example page](https://github.com/ing-bank/lion/blob/
|
|
175
|
+
➡️ See [it on the example page](https://github.com/ing-bank/lion/blob/cd21c9386e7a9818a71d3e12d7b46c32b7fe76ff/docs/fundamentals/tools/singleton-manager/example-fail/index.md). <br>
|
|
176
176
|
➡️ See [the code](https://github.com/ing-bank/lion/tree/master/docs/fundamentals/tools/singleton-manager/example-fail/demo-app.js).
|
|
177
177
|
|
|
178
178
|
---
|
|
@@ -215,7 +215,7 @@ See it in action
|
|
|
215
215
|
npm run start:singleton
|
|
216
216
|
```
|
|
217
217
|
|
|
218
|
-
➡️ See [it on the example page](https://github.com/ing-bank/lion/blob/
|
|
218
|
+
➡️ See [it on the example page](https://github.com/ing-bank/lion/blob/cd21c9386e7a9818a71d3e12d7b46c32b7fe76ff/docs/fundamentals/tools/singleton-manager/example-success/index.md). <br>
|
|
219
219
|
➡️ See [the code](https://github.com/ing-bank/lion/tree/master/docs/fundamentals/tools/singleton-manager/example-success/demo-app.js).
|
|
220
220
|
|
|
221
221
|
---
|
|
@@ -256,7 +256,7 @@ See it in action
|
|
|
256
256
|
npm run start:singleton-complex
|
|
257
257
|
```
|
|
258
258
|
|
|
259
|
-
➡️ See [it on the example page](https://github.com/ing-bank/lion/blob/
|
|
259
|
+
➡️ See [it on the example page](https://github.com/ing-bank/lion/blob/cd21c9386e7a9818a71d3e12d7b46c32b7fe76ff/docs/fundamentals/tools/singleton-manager/example-complex/index.md). <br>
|
|
260
260
|
➡️ See [the code](https://github.com/ing-bank/lion/tree/master/docs/fundamentals/tools/singleton-manager/example-complex/demo-app.js).
|
|
261
261
|
|
|
262
262
|
---
|
|
@@ -87,9 +87,9 @@ if (!customElements.get('dummy-slider')) {
|
|
|
87
87
|
}
|
|
88
88
|
```
|
|
89
89
|
|
|
90
|
-
Custom Fields can be created in just a few steps. All you need is an interaction element (like for instance a slider, a listbox or a combobox) and connect it to the [LionField](https://github.com/ing-bank/lion/blob/
|
|
90
|
+
Custom Fields can be created in just a few steps. All you need is an interaction element (like for instance a slider, a listbox or a combobox) and connect it to the [LionField](https://github.com/ing-bank/lion/blob/cd21c9386e7a9818a71d3e12d7b46c32b7fe76ff/docs/components/input/overview.md).
|
|
91
91
|
|
|
92
|
-
> In case you want to extend a native element, follow [Extend a native Input](https://github.com/ing-bank/lion/blob/
|
|
92
|
+
> In case you want to extend a native element, follow [Extend a native Input](https://github.com/ing-bank/lion/blob/cd21c9386e7a9818a71d3e12d7b46c32b7fe76ff/docs/guides/how-to/extend-a-native-input.md).
|
|
93
93
|
|
|
94
94
|
## A) an interaction element
|
|
95
95
|
|
|
@@ -138,7 +138,7 @@ export const createAnInteractiveElement = () => {
|
|
|
138
138
|
## B) your LionField extension
|
|
139
139
|
|
|
140
140
|
Now we want to integrate the slider in our form system to enrich the user interface, get
|
|
141
|
-
validation support and all other [benefits of LionField](https://github.com/ing-bank/lion/blob/
|
|
141
|
+
validation support and all other [benefits of LionField](https://github.com/ing-bank/lion/blob/cd21c9386e7a9818a71d3e12d7b46c32b7fe76ff/docs/components/input/overview.md).
|
|
142
142
|
We start by creating a component `<slider-field>` that extends from `LionField`.
|
|
143
143
|
Then we follow the steps below:
|
|
144
144
|
|
|
@@ -151,7 +151,7 @@ Then we follow the steps below:
|
|
|
151
151
|
|
|
152
152
|
The `user-input-changed` event is listened to by the FormatMixin: it should be regarded as the
|
|
153
153
|
equivalent of the `input` event of the platform, but for custom built interaction elements.
|
|
154
|
-
You now synchronized [modelValue](https://github.com/ing-bank/lion/blob/
|
|
154
|
+
You now synchronized [modelValue](https://github.com/ing-bank/lion/blob/cd21c9386e7a9818a71d3e12d7b46c32b7fe76ff/docs/fundamentals/systems/form/model-value.md), which can be regarded as
|
|
155
155
|
the glue to integrate all other functionality like parsing/formatting/serializing, validating,
|
|
156
156
|
tracking interaction states etc.
|
|
157
157
|
|
|
@@ -159,7 +159,7 @@ Then we follow the steps below:
|
|
|
159
159
|
> because those properties will lose their reactivity (they won't be considered anymore in the
|
|
160
160
|
> update loop of LitElement).
|
|
161
161
|
> Whenever a .modelValue/.formattedValue/.serializedValue needs to be computed, use
|
|
162
|
-
> [parser/formatter/serializer](https://github.com/ing-bank/lion/blob/
|
|
162
|
+
> [parser/formatter/serializer](https://github.com/ing-bank/lion/blob/cd21c9386e7a9818a71d3e12d7b46c32b7fe76ff/docs/fundamentals/systems/form/formatting-and-parsing.md)
|
|
163
163
|
|
|
164
164
|
Implement with the following code:
|
|
165
165
|
|
|
@@ -39,7 +39,7 @@ Large or complex forms might need to be split up into multiple files. This compo
|
|
|
39
39
|
|
|
40
40
|
In the latter case: make sure that your components don't have a shadow root. This can be achieved by rendering into Light DOM. The form registration mechanism relies on light dom by design: as soon as you do start to use shadow roots, you will notice that your form components won't register themselves anymore to their parents.
|
|
41
41
|
|
|
42
|
-
> Today, rendering to light dom is the only way to [stay accessible](https://github.com/ing-bank/lion/blob/
|
|
42
|
+
> Today, rendering to light dom is the only way to [stay accessible](https://github.com/ing-bank/lion/blob/cd21c9386e7a9818a71d3e12d7b46c32b7fe76ff/docs/fundamentals/rationales/accessibility.md#shadow-roots-and-accessibility).
|
|
43
43
|
|
|
44
44
|
### Example of a component that renders into Light DOM
|
|
45
45
|
|
|
@@ -86,7 +86,7 @@ Extending form components is not recommended for Application Developers: it shou
|
|
|
86
86
|
This team will add the styling and default configuration needed to make it fit the particular Design System.
|
|
87
87
|
|
|
88
88
|
With the toolbox provided by the team that creates your Design System, you should be able to build all your forms. Only if you have a really good reason, look into
|
|
89
|
-
[exceptional cases](https://github.com/ing-bank/lion/blob/
|
|
89
|
+
[exceptional cases](https://github.com/ing-bank/lion/blob/cd21c9386e7a9818a71d3e12d7b46c32b7fe76ff/docs/guides/how-to/#exceptional-cases) below.
|
|
90
90
|
|
|
91
91
|
### Exceptional cases
|
|
92
92
|
|
|
@@ -94,8 +94,8 @@ If the form component you need is still missing, you have two options:
|
|
|
94
94
|
|
|
95
95
|
- is it a generic primitive that should be part of Lion? Request it in [Lion discussions](https://github.com/ing-bank/lion/discussions)
|
|
96
96
|
- is it a non generic component that is unique to your app?
|
|
97
|
-
- follow [create a custom field](https://github.com/ing-bank/lion/blob/
|
|
98
|
-
- follow [extend a native input](https://github.com/ing-bank/lion/blob/
|
|
97
|
+
- follow [create a custom field](https://github.com/ing-bank/lion/blob/cd21c9386e7a9818a71d3e12d7b46c32b7fe76ff/docs/guides/how-to/create-a-custom-field.md)
|
|
98
|
+
- follow [extend a native input](https://github.com/ing-bank/lion/blob/cd21c9386e7a9818a71d3e12d7b46c32b7fe76ff/docs/guides/how-to/extend-a-native-input.md)
|
|
99
99
|
|
|
100
100
|
It's also possible to extend other components, like LionListbox or LionCombobox. You need to be aware that you're building on top of protected apis.
|
|
101
101
|
Changing/overriding functionality is only recommended if the source code in `form-core` is fully understood.
|
|
@@ -23,9 +23,9 @@ import '../../fundamentals/systems/form/assets/h-output.js';
|
|
|
23
23
|
loadDefaultFeedbackMessages();
|
|
24
24
|
```
|
|
25
25
|
|
|
26
|
-
Input fields can be created by extending [LionInput](https://github.com/ing-bank/lion/blob/
|
|
26
|
+
Input fields can be created by extending [LionInput](https://github.com/ing-bank/lion/blob/cd21c9386e7a9818a71d3e12d7b46c32b7fe76ff/docs/components/input/overview.md).
|
|
27
27
|
|
|
28
|
-
> In case you want to wrap a custom form element, follow [Create a custom Field](https://github.com/ing-bank/lion/blob/
|
|
28
|
+
> In case you want to wrap a custom form element, follow [Create a custom Field](https://github.com/ing-bank/lion/blob/cd21c9386e7a9818a71d3e12d7b46c32b7fe76ff/docs/guides/how-to/create-a-custom-field.md).
|
|
29
29
|
|
|
30
30
|
For this tutorial, we create an input that wraps native `input[type=datetime-local]`.
|
|
31
31
|
This is as simple as adding a type:
|
package/docs/guides/index.md
CHANGED
|
@@ -22,9 +22,9 @@ Developers consuming our web components inside an application (not extending the
|
|
|
22
22
|
`Application Developers` are only allowed to interact with `public` properties and methods.
|
|
23
23
|
Can be abbreviated as `AD`. Sometimes also called `Consuming Developer`.
|
|
24
24
|
|
|
25
|
-
- [Definitions and Terms](https://github.com/ing-bank/lion/blob/
|
|
26
|
-
- [Styling](https://github.com/ing-bank/lion/blob/
|
|
27
|
-
- [Scoped Elements](https://github.com/ing-bank/lion/blob/
|
|
25
|
+
- [Definitions and Terms](https://github.com/ing-bank/lion/blob/cd21c9386e7a9818a71d3e12d7b46c32b7fe76ff/docs/guides/principles/definitions-and-terms.md)
|
|
26
|
+
- [Styling](https://github.com/ing-bank/lion/blob/cd21c9386e7a9818a71d3e12d7b46c32b7fe76ff/docs/guides/principles/styling.md)
|
|
27
|
+
- [Scoped Elements](https://github.com/ing-bank/lion/blob/cd21c9386e7a9818a71d3e12d7b46c32b7fe76ff/docs/guides/principles/scoped-elements.md)
|
|
28
28
|
|
|
29
29
|
## Extending Developer
|
|
30
30
|
|
|
@@ -32,13 +32,13 @@ Developers extending our web components, for instance: `class MaterialInput exte
|
|
|
32
32
|
|
|
33
33
|
Especially for subclassers we have some extra documentation:
|
|
34
34
|
|
|
35
|
-
- [Subclasser APIs](https://github.com/ing-bank/lion/blob/
|
|
36
|
-
- [Extend documentation](https://github.com/ing-bank/lion/blob/
|
|
35
|
+
- [Subclasser APIs](https://github.com/ing-bank/lion/blob/cd21c9386e7a9818a71d3e12d7b46c32b7fe76ff/docs/guides/principles/subclasser-apis.md)
|
|
36
|
+
- [Extend documentation](https://github.com/ing-bank/lion/blob/cd21c9386e7a9818a71d3e12d7b46c32b7fe76ff/docs/blog/extending-documentation.md)
|
|
37
37
|
|
|
38
38
|
## How To
|
|
39
39
|
|
|
40
40
|
Next to that we have some specific "How To" documentations.
|
|
41
41
|
|
|
42
|
-
- [Get started](https://github.com/ing-bank/lion/blob/
|
|
43
|
-
- [Create a custom field](https://github.com/ing-bank/lion/blob/
|
|
44
|
-
- [Extend a native input](https://github.com/ing-bank/lion/blob/
|
|
42
|
+
- [Get started](https://github.com/ing-bank/lion/blob/cd21c9386e7a9818a71d3e12d7b46c32b7fe76ff/docs/guides/how-to/get-started.md)
|
|
43
|
+
- [Create a custom field](https://github.com/ing-bank/lion/blob/cd21c9386e7a9818a71d3e12d7b46c32b7fe76ff/docs/guides/how-to/create-a-custom-field.md)
|
|
44
|
+
- [Extend a native input](https://github.com/ing-bank/lion/blob/cd21c9386e7a9818a71d3e12d7b46c32b7fe76ff/docs/guides/how-to/extend-a-native-input.md)
|
|
@@ -22,9 +22,9 @@ Developers consuming our web components inside an application (not extending the
|
|
|
22
22
|
`Application Developers` are only allowed to interact with `public` properties and methods.
|
|
23
23
|
Can be abbreviated as `AD`. Sometimes also called `Consuming Developer`.
|
|
24
24
|
|
|
25
|
-
- [Definitions and Terms](https://github.com/ing-bank/lion/blob/
|
|
26
|
-
- [Styling](https://github.com/ing-bank/lion/blob/
|
|
27
|
-
- [Scoped Elements](https://github.com/ing-bank/lion/blob/
|
|
25
|
+
- [Definitions and Terms](https://github.com/ing-bank/lion/blob/cd21c9386e7a9818a71d3e12d7b46c32b7fe76ff/docs/guides/principles/definitions-and-terms.md)
|
|
26
|
+
- [Styling](https://github.com/ing-bank/lion/blob/cd21c9386e7a9818a71d3e12d7b46c32b7fe76ff/docs/guides/principles/styling.md)
|
|
27
|
+
- [Scoped Elements](https://github.com/ing-bank/lion/blob/cd21c9386e7a9818a71d3e12d7b46c32b7fe76ff/docs/guides/principles/scoped-elements.md)
|
|
28
28
|
|
|
29
29
|
## Extending Developer
|
|
30
30
|
|
|
@@ -32,5 +32,5 @@ Developers extending our web components, for instance: `class MaterialInput exte
|
|
|
32
32
|
|
|
33
33
|
Especially for subclassers we have some extra documentation:
|
|
34
34
|
|
|
35
|
-
- [Subclasser APIs](https://github.com/ing-bank/lion/blob/
|
|
36
|
-
- [Extend documentation](https://github.com/ing-bank/lion/blob/
|
|
35
|
+
- [Subclasser APIs](https://github.com/ing-bank/lion/blob/cd21c9386e7a9818a71d3e12d7b46c32b7fe76ff/docs/guides/principles/subclasser-apis.md)
|
|
36
|
+
- [Extend documentation](https://github.com/ing-bank/lion/blob/cd21c9386e7a9818a71d3e12d7b46c32b7fe76ff/docs/blog/extending-documentation.md)
|
|
@@ -31,7 +31,7 @@ Examples for both categories can be found below:
|
|
|
31
31
|
- Accessibility examples:
|
|
32
32
|
- Content (for instance a caption in a table) can be `visually hidden`: it will be
|
|
33
33
|
readable by screen readers, but invisible for end users.
|
|
34
|
-
- When an html table is used, we allow [subclassers](https://github.com/ing-bank/lion/blob/
|
|
34
|
+
- When an html table is used, we allow [subclassers](https://github.com/ing-bank/lion/blob/cd21c9386e7a9818a71d3e12d7b46c32b7fe76ff/docs/guides/principles/subclasser-apis.md) to override the display property (`table-cell`) to `flex`. By putting the proper accessible roles (`role="cell"`) in the markup, we guarantee our markup stays accessible.
|
|
35
35
|
|
|
36
36
|
Although Lion components try to stay as unbiased as possible with regard to styling, defaults will be needed. In these cases we try to follow the platform as much as possible. If the platform doesn't provide defaults, the largest common denominator across existing UI systems is taken as a lead.
|
|
37
37
|
|
package/exports/overlays.js
CHANGED
|
@@ -9,7 +9,6 @@ export { withModalDialogConfig } from '../components/overlays/src/configurations
|
|
|
9
9
|
export { withDropdownConfig } from '../components/overlays/src/configurations/withDropdownConfig.js';
|
|
10
10
|
export { withTooltipConfig } from '../components/overlays/src/configurations/withTooltipConfig.js';
|
|
11
11
|
|
|
12
|
-
export { containFocus, rotateFocus } from '../components/overlays/src/utils/contain-focus.js';
|
|
13
12
|
export { deepContains } from '../components/overlays/src/utils/deep-contains.js';
|
|
14
13
|
// re-export via this entrypoint for backwards compatibility
|
|
15
14
|
export { getDeepActiveElement } from '../components/core/src/getDeepActiveElement.js';
|
package/overlays.js
CHANGED
|
@@ -6,7 +6,6 @@ export { withBottomSheetConfig } from './components/overlays/src/configurations/
|
|
|
6
6
|
export { withModalDialogConfig } from './components/overlays/src/configurations/withModalDialogConfig.js';
|
|
7
7
|
export { withDropdownConfig } from './components/overlays/src/configurations/withDropdownConfig.js';
|
|
8
8
|
export { withTooltipConfig } from './components/overlays/src/configurations/withTooltipConfig.js';
|
|
9
|
-
export { containFocus, rotateFocus } from './components/overlays/src/utils/contain-focus.js';
|
|
10
9
|
export { deepContains } from './components/overlays/src/utils/deep-contains.js';
|
|
11
10
|
// re-export via this entrypoint for backwards compatibility
|
|
12
11
|
export { getDeepActiveElement } from './components/core/src/getDeepActiveElement.js';
|
package/package.json
CHANGED
|
@@ -1,202 +0,0 @@
|
|
|
1
|
-
/* eslint-disable no-param-reassign */
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Implementation based on: https://github.com/PolymerElements/iron-overlay-behavior/blob/master/iron-focusables-helper.html
|
|
5
|
-
* The original implementation does not work for non-Polymer web components,
|
|
6
|
-
* and contains several bugs on IE11.
|
|
7
|
-
*/
|
|
8
|
-
|
|
9
|
-
import { getDeepActiveElement } from '../../../core/src/getDeepActiveElement.js';
|
|
10
|
-
import { getFocusableElements } from './get-focusable-elements.js';
|
|
11
|
-
import { deepContains } from './deep-contains.js';
|
|
12
|
-
import { keyCodes } from './key-codes.js';
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* Rotates focus within a list of elements. If shift key was not pressed and focus
|
|
16
|
-
* is on last item, puts focus on the first item. Reversed if shift key.
|
|
17
|
-
*
|
|
18
|
-
* @param {HTMLElement} rootElement The root element
|
|
19
|
-
* @param {KeyboardEvent} e The keyboard event
|
|
20
|
-
*/
|
|
21
|
-
export function rotateFocus(rootElement, e) {
|
|
22
|
-
// Find focusable elements
|
|
23
|
-
const els = getFocusableElements(rootElement);
|
|
24
|
-
// Determine the focus rotation boundaries.
|
|
25
|
-
let boundaryEls;
|
|
26
|
-
|
|
27
|
-
// If more than two elements, take the first and last
|
|
28
|
-
if (els.length >= 2) {
|
|
29
|
-
boundaryEls = [els[0], els[els.length - 1]];
|
|
30
|
-
|
|
31
|
-
// If 1 element, it is the boundary
|
|
32
|
-
} else if (els.length === 1) {
|
|
33
|
-
boundaryEls = [els[0], els[0]];
|
|
34
|
-
|
|
35
|
-
// If no focusable elements, root becomes the boundary
|
|
36
|
-
} else {
|
|
37
|
-
boundaryEls = [rootElement, rootElement];
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
// Reverse direction of boundaries if shift key was pressed
|
|
41
|
-
if (e.shiftKey) {
|
|
42
|
-
boundaryEls.reverse();
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
// Take first and last elements within boundary
|
|
46
|
-
const [first, last] = boundaryEls;
|
|
47
|
-
|
|
48
|
-
// Get the currently focused element
|
|
49
|
-
const activeElement = /** @type {HTMLElement} */ (getDeepActiveElement());
|
|
50
|
-
|
|
51
|
-
/**
|
|
52
|
-
* If currently focused on the root element or an element contained within the root element:
|
|
53
|
-
* allow native browser behavior (tab to the next node in DOM order).
|
|
54
|
-
*
|
|
55
|
-
* If currently focused on the last focusable element within the root element, or on an element
|
|
56
|
-
* outside of the root element: redirect focus to the first focusable element.
|
|
57
|
-
*/
|
|
58
|
-
if (activeElement === rootElement || (els.includes(activeElement) && last !== activeElement)) {
|
|
59
|
-
return;
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
e.preventDefault();
|
|
63
|
-
first.focus();
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
/**
|
|
67
|
-
* Contains focus within given root element. When focus is on the last focusable
|
|
68
|
-
* element inside the root element, the next focus will be redirected to the first
|
|
69
|
-
* focusable element.
|
|
70
|
-
*
|
|
71
|
-
* @param {HTMLElement} rootElement The element to contain focus within
|
|
72
|
-
* @returns {{ disconnect: () => void }} handler with a disconnect callback
|
|
73
|
-
*/
|
|
74
|
-
export function containFocus(rootElement) {
|
|
75
|
-
const focusableElements = getFocusableElements(rootElement);
|
|
76
|
-
// Initial focus goes to first element with autofocus, or the root element
|
|
77
|
-
const initialFocus = focusableElements.find(e => e.hasAttribute('autofocus')) || rootElement;
|
|
78
|
-
/** @type {HTMLElement} */
|
|
79
|
-
let tabDetectionElement;
|
|
80
|
-
/** @type {MutationObserver} */
|
|
81
|
-
let rootElementMutationObserver;
|
|
82
|
-
|
|
83
|
-
// If root element will receive focus, it should have a tabindex of -1.
|
|
84
|
-
// This makes it focusable through js, but it won't appear in the tab order
|
|
85
|
-
if (initialFocus === rootElement) {
|
|
86
|
-
rootElement.tabIndex = -1;
|
|
87
|
-
rootElement.style.setProperty('outline', 'none');
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
// Focus first focusable element
|
|
91
|
-
initialFocus.focus();
|
|
92
|
-
|
|
93
|
-
/**
|
|
94
|
-
* Ensures focus stays inside root element on tab
|
|
95
|
-
* @param {KeyboardEvent} e
|
|
96
|
-
*/
|
|
97
|
-
function handleKeydown(e) {
|
|
98
|
-
if (e.keyCode === keyCodes.tab) {
|
|
99
|
-
rotateFocus(rootElement, e);
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
function createHelpersDetectingTabDirection() {
|
|
104
|
-
tabDetectionElement = document.createElement('div');
|
|
105
|
-
tabDetectionElement.style.display = 'none';
|
|
106
|
-
tabDetectionElement.setAttribute('data-is-tab-detection-element', '');
|
|
107
|
-
rootElement.insertBefore(tabDetectionElement, rootElement.children[0]);
|
|
108
|
-
|
|
109
|
-
rootElementMutationObserver = new MutationObserver(mutationsList => {
|
|
110
|
-
for (const mutation of mutationsList) {
|
|
111
|
-
if (mutation.type === 'childList') {
|
|
112
|
-
const tabDetectionElIsMissing = !Array.from(rootElement.children).find(el =>
|
|
113
|
-
el.hasAttribute('data-is-tab-detection-element'),
|
|
114
|
-
);
|
|
115
|
-
const foundTabDetectionElInMutations = Array.from(mutation.addedNodes).find(
|
|
116
|
-
/** @param {Node} el */ el =>
|
|
117
|
-
el instanceof HTMLElement && el.hasAttribute('data-is-tab-detection-element'),
|
|
118
|
-
);
|
|
119
|
-
// Prevent infinite loop by detecting that mutation event is not from adding the tab detection el
|
|
120
|
-
if (tabDetectionElIsMissing && !foundTabDetectionElInMutations) {
|
|
121
|
-
rootElementMutationObserver.disconnect();
|
|
122
|
-
createHelpersDetectingTabDirection();
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
});
|
|
127
|
-
rootElementMutationObserver.observe(rootElement, { childList: true });
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
function isForwardTabInWindow() {
|
|
131
|
-
const compareMask = tabDetectionElement.compareDocumentPosition(
|
|
132
|
-
/** @type {Element} */ (document.activeElement),
|
|
133
|
-
);
|
|
134
|
-
return compareMask === Node.DOCUMENT_POSITION_PRECEDING;
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
/**
|
|
138
|
-
* @param {Object} opts
|
|
139
|
-
* @param {boolean} [opts.resetToRoot]
|
|
140
|
-
* @desc When we simulate a modal dialog, we need to restore the focus to the first or last
|
|
141
|
-
* element of the rootElement
|
|
142
|
-
*/
|
|
143
|
-
function setFocusInRootElement({ resetToRoot = false } = {}) {
|
|
144
|
-
if (deepContains(rootElement, /** @type {HTMLElement} */ (getDeepActiveElement()))) {
|
|
145
|
-
return;
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
let nextActive;
|
|
149
|
-
if (resetToRoot) {
|
|
150
|
-
nextActive = rootElement;
|
|
151
|
-
} else {
|
|
152
|
-
nextActive = focusableElements[isForwardTabInWindow() ? 0 : focusableElements.length - 1];
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
if (nextActive) {
|
|
156
|
-
nextActive.focus();
|
|
157
|
-
}
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
function handleFocusin() {
|
|
161
|
-
window.removeEventListener('focusin', handleFocusin);
|
|
162
|
-
setFocusInRootElement();
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
function handleFocusout() {
|
|
166
|
-
/**
|
|
167
|
-
* There is a moment in time between focusout and focusin (when focus shifts)
|
|
168
|
-
* where the activeElement is reset to body first. So we use an async task to check
|
|
169
|
-
* a little bit later for activeElement, so we don't get a false positive.
|
|
170
|
-
*
|
|
171
|
-
* We used to check for focusin event for this, however,
|
|
172
|
-
* it can happen that focusout happens, but focusin never does, e.g. click outside but no focusable
|
|
173
|
-
* element is found to focus. If this happens, we should take the focus back to the rootElement.
|
|
174
|
-
*/
|
|
175
|
-
setTimeout(() => {
|
|
176
|
-
if (!deepContains(rootElement, /** @type {HTMLElement} */ (getDeepActiveElement()))) {
|
|
177
|
-
setFocusInRootElement({ resetToRoot: true });
|
|
178
|
-
}
|
|
179
|
-
});
|
|
180
|
-
|
|
181
|
-
window.addEventListener('focusin', handleFocusin);
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
function disconnect() {
|
|
185
|
-
window.removeEventListener('keydown', handleKeydown);
|
|
186
|
-
window.removeEventListener('focusin', handleFocusin);
|
|
187
|
-
window.removeEventListener('focusout', handleFocusout);
|
|
188
|
-
// Guard this, since we also disconnect if we notice a missing tab
|
|
189
|
-
// detection element. We reinsert it, so it's okay to not fail here.
|
|
190
|
-
rootElementMutationObserver.disconnect();
|
|
191
|
-
if (Array.from(rootElement.children).includes(tabDetectionElement)) {
|
|
192
|
-
rootElement.removeChild(tabDetectionElement);
|
|
193
|
-
}
|
|
194
|
-
rootElement.style.removeProperty('outline');
|
|
195
|
-
}
|
|
196
|
-
|
|
197
|
-
window.addEventListener('keydown', handleKeydown);
|
|
198
|
-
window.addEventListener('focusout', handleFocusout);
|
|
199
|
-
createHelpersDetectingTabDirection();
|
|
200
|
-
|
|
201
|
-
return { disconnect };
|
|
202
|
-
}
|