@1024pix/pix-ui 18.0.2 → 18.1.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/CHANGELOG.md +6 -0
- package/addon/components/pix-sidebar.hbs +4 -4
- package/addon/components/pix-sidebar.js +5 -0
- package/addon/styles/_trap-focus.scss +3 -0
- package/addon/styles/addon.scss +1 -0
- package/addon/utils/unique-id.js +5 -0
- package/app/modifiers/trap-focus.js +10 -0
- package/app/stories/pix-sidebar.stories.js +3 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -7,13 +7,13 @@
|
|
|
7
7
|
<div
|
|
8
8
|
class="pix-sidebar {{unless @showSidebar ' pix-sidebar--hidden'}}"
|
|
9
9
|
role="dialog"
|
|
10
|
-
aria-labelledby="sidebar-title"
|
|
11
|
-
aria-describedby="sidebar-content"
|
|
10
|
+
aria-labelledby="sidebar-title--{{this.id}}"
|
|
11
|
+
aria-describedby="sidebar-content--{{this.id}}"
|
|
12
12
|
aria-modal="true"
|
|
13
13
|
...attributes
|
|
14
14
|
>
|
|
15
15
|
<header class="pix-sidebar__header">
|
|
16
|
-
<h1 id="sidebar-title" class="pix-sidebar__title">{{@title}}</h1>
|
|
16
|
+
<h1 id="sidebar-title--{{this.id}}" class="pix-sidebar__title">{{@title}}</h1>
|
|
17
17
|
<PixIconButton
|
|
18
18
|
@icon="xmark"
|
|
19
19
|
@triggerAction={{@onClose}}
|
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
class="pix-sidebar__close-button"
|
|
24
24
|
/>
|
|
25
25
|
</header>
|
|
26
|
-
<main id="sidebar-content" class="pix-sidebar__content">
|
|
26
|
+
<main id="sidebar-content--{{this.id}}" class="pix-sidebar__content">
|
|
27
27
|
{{yield to="content"}}
|
|
28
28
|
</main>
|
|
29
29
|
<footer class="pix-sidebar__footer">
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import Component from '@glimmer/component';
|
|
2
2
|
import { action } from '@ember/object';
|
|
3
|
+
import uniqueId from '@1024pix/pix-ui/utils/unique-id';
|
|
3
4
|
|
|
4
5
|
export default class PixSidebar extends Component {
|
|
5
6
|
constructor(...args) {
|
|
@@ -20,4 +21,8 @@ export default class PixSidebar extends Component {
|
|
|
20
21
|
isClickOnOverlay(event) {
|
|
21
22
|
return event.target.classList.contains('pix-sidebar__overlay');
|
|
22
23
|
}
|
|
24
|
+
|
|
25
|
+
get id() {
|
|
26
|
+
return uniqueId();
|
|
27
|
+
}
|
|
23
28
|
}
|
package/addon/styles/addon.scss
CHANGED
|
@@ -6,9 +6,11 @@ export default modifier(function trapFocus(element, [isOpen]) {
|
|
|
6
6
|
const [firstFocusableElement] = findFocusableElements(element);
|
|
7
7
|
|
|
8
8
|
if (isOpen) {
|
|
9
|
+
preventPageScrolling();
|
|
9
10
|
sourceActiveElement = document.activeElement;
|
|
10
11
|
focusElement(firstFocusableElement, element);
|
|
11
12
|
} else if (sourceActiveElement) {
|
|
13
|
+
allowPageScrolling();
|
|
12
14
|
focusElement(sourceActiveElement, element);
|
|
13
15
|
}
|
|
14
16
|
|
|
@@ -58,6 +60,14 @@ function focusElement(elementToFocus, element) {
|
|
|
58
60
|
};
|
|
59
61
|
}
|
|
60
62
|
|
|
63
|
+
function preventPageScrolling() {
|
|
64
|
+
document.body.classList.add('body__trap-focus');
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
function allowPageScrolling() {
|
|
68
|
+
document.body.classList.remove('body__trap-focus');
|
|
69
|
+
}
|
|
70
|
+
|
|
61
71
|
function hasTransitionDuration(element) {
|
|
62
72
|
return hasDurationByKey(element, 'transition-duration');
|
|
63
73
|
}
|
|
@@ -17,7 +17,9 @@ export const Template = (args) => {
|
|
|
17
17
|
</div>
|
|
18
18
|
</:footer>
|
|
19
19
|
</PixSidebar>
|
|
20
|
-
<
|
|
20
|
+
<div style="display:flex; justify-content:center; align-items:center; height:105vh;">
|
|
21
|
+
<PixButton @triggerAction={{fn (mut showSidebar) (not showSidebar)}} style="height:45px">Ouvrir la sidebar</PixButton>
|
|
22
|
+
</div>
|
|
21
23
|
`,
|
|
22
24
|
context: args,
|
|
23
25
|
};
|