@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 CHANGED
@@ -1,5 +1,11 @@
1
1
  # Pix-UI Changelog
2
2
 
3
+ ## v18.1.0 (15/09/2022)
4
+
5
+
6
+ ### :rocket: Amélioration
7
+ - [#253](https://github.com/1024pix/pix-ui/pull/253) [FEATURE] Améliorer de l'accessibilité de Pix-Sidebar.
8
+
3
9
  ## v18.0.2 (06/09/2022)
4
10
 
5
11
 
@@ -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
  }
@@ -0,0 +1,3 @@
1
+ .body__trap-focus {
2
+ overflow: hidden;
3
+ }
@@ -28,6 +28,7 @@
28
28
  @import 'pix-dropdown';
29
29
  @import 'pix-pagination';
30
30
  @import 'pix-checkbox';
31
+ @import 'trap-focus';
31
32
 
32
33
  html {
33
34
  font-size: 16px;
@@ -0,0 +1,5 @@
1
+ export default function uniqueId() {
2
+ return ([3e7] + -1e3 + -4e3 + -2e3 + -1e11).replace(/[0-3]/g, (a) =>
3
+ ((a * 4) ^ ((Math.random() * 16) >> (a & 2))).toString(16)
4
+ );
5
+ }
@@ -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
- <PixButton @triggerAction={{fn (mut showSidebar) (not showSidebar)}}>Ouvrir la sidebar</PixButton>
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
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@1024pix/pix-ui",
3
- "version": "18.0.2",
3
+ "version": "18.1.0",
4
4
  "description": "Pix-UI is the implementation of Pix design principles and guidelines for its products.",
5
5
  "keywords": [
6
6
  "ember-addon"