@1024pix/pix-ui 17.2.1 → 18.0.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-modal.hbs +2 -2
- package/addon/components/pix-sidebar.hbs +1 -1
- package/addon/styles/_pix-modal.scss +6 -0
- package/app/modifiers/trap-focus.js +84 -34
- package/app/stories/pix-modal.stories.js +29 -19
- package/app/stories/pix-modal.stories.mdx +1 -1
- package/app/stories/pix-sidebar.stories.js +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,45 +1,25 @@
|
|
|
1
1
|
import { modifier } from 'ember-modifier';
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
const [firstFocusableElement] = findFocusableElements(element);
|
|
5
|
-
|
|
6
|
-
firstFocusableElement.focus();
|
|
7
|
-
|
|
8
|
-
function handleKeyDown(event) {
|
|
9
|
-
const TAB_KEY = 9;
|
|
10
|
-
const focusableElements = findFocusableElements(element);
|
|
11
|
-
const [firstFocusableElement] = focusableElements;
|
|
12
|
-
const lastFocusableElement = focusableElements[focusableElements.length - 1];
|
|
13
|
-
|
|
14
|
-
if (event.keyCode !== TAB_KEY) {
|
|
15
|
-
return;
|
|
16
|
-
}
|
|
3
|
+
let sourceActiveElement = null;
|
|
17
4
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
event.preventDefault();
|
|
21
|
-
lastFocusableElement.focus();
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
function handleForwardTab() {
|
|
26
|
-
if (document.activeElement === lastFocusableElement) {
|
|
27
|
-
event.preventDefault();
|
|
28
|
-
firstFocusableElement.focus();
|
|
29
|
-
}
|
|
30
|
-
}
|
|
5
|
+
export default modifier(function trapFocus(element, [isOpen]) {
|
|
6
|
+
const [firstFocusableElement] = findFocusableElements(element);
|
|
31
7
|
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
8
|
+
if (isOpen) {
|
|
9
|
+
sourceActiveElement = document.activeElement;
|
|
10
|
+
focusElement(firstFocusableElement, element);
|
|
11
|
+
} else {
|
|
12
|
+
focusElement(sourceActiveElement, element);
|
|
37
13
|
}
|
|
38
14
|
|
|
39
|
-
element.addEventListener('keydown',
|
|
15
|
+
element.addEventListener('keydown', (event) => {
|
|
16
|
+
handleKeyDown(event, element);
|
|
17
|
+
});
|
|
40
18
|
|
|
41
19
|
return () => {
|
|
42
|
-
element.removeEventListener('keydown',
|
|
20
|
+
element.removeEventListener('keydown', (event) => {
|
|
21
|
+
handleKeyDown(event, element);
|
|
22
|
+
});
|
|
43
23
|
};
|
|
44
24
|
});
|
|
45
25
|
|
|
@@ -50,3 +30,73 @@ function findFocusableElements(element) {
|
|
|
50
30
|
),
|
|
51
31
|
].filter((el) => !el.hasAttribute('disabled') && !el.getAttribute('aria-hidden'));
|
|
52
32
|
}
|
|
33
|
+
|
|
34
|
+
function focusElement(elementToFocus, element) {
|
|
35
|
+
let focusOnce = false;
|
|
36
|
+
|
|
37
|
+
const handleTransitionEnd = () => {
|
|
38
|
+
if (!focusOnce) {
|
|
39
|
+
elementToFocus.focus();
|
|
40
|
+
focusOnce = true;
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
if (hasTransitionDuration(element)) {
|
|
45
|
+
element.addEventListener('transitionend', handleTransitionEnd);
|
|
46
|
+
} else if (hasAnimationDuration(element)) {
|
|
47
|
+
element.addEventListener('animationend', handleTransitionEnd);
|
|
48
|
+
} else {
|
|
49
|
+
elementToFocus.focus();
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
return () => {
|
|
53
|
+
if (hasTransitionDuration(element)) {
|
|
54
|
+
element.removeEventListener('transitionend', handleTransitionEnd);
|
|
55
|
+
} else if (hasAnimationDuration(element)) {
|
|
56
|
+
element.removeEventListener('animationend', handleTransitionEnd);
|
|
57
|
+
}
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
function hasTransitionDuration(element) {
|
|
62
|
+
return hasDurationByKey(element, 'transition-duration');
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
function hasAnimationDuration(element) {
|
|
66
|
+
return hasDurationByKey(element, 'animation-duration');
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
function hasDurationByKey(element, key) {
|
|
70
|
+
return !['', '0s'].includes(getComputedStyle(element, null).getPropertyValue(key));
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
function handleKeyDown(event, element) {
|
|
74
|
+
const TAB_KEY = 9;
|
|
75
|
+
const focusableElements = findFocusableElements(element);
|
|
76
|
+
const [firstFocusableElement] = focusableElements;
|
|
77
|
+
const lastFocusableElement = focusableElements[focusableElements.length - 1];
|
|
78
|
+
|
|
79
|
+
if (event.keyCode !== TAB_KEY) {
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
const handleBackwardTab = () => {
|
|
84
|
+
if (document.activeElement === firstFocusableElement) {
|
|
85
|
+
event.preventDefault();
|
|
86
|
+
lastFocusableElement.focus();
|
|
87
|
+
}
|
|
88
|
+
};
|
|
89
|
+
|
|
90
|
+
const handleForwardTab = () => {
|
|
91
|
+
if (document.activeElement === lastFocusableElement) {
|
|
92
|
+
event.preventDefault();
|
|
93
|
+
firstFocusableElement.focus();
|
|
94
|
+
}
|
|
95
|
+
};
|
|
96
|
+
|
|
97
|
+
if (event.shiftKey) {
|
|
98
|
+
handleBackwardTab();
|
|
99
|
+
} else {
|
|
100
|
+
handleForwardTab();
|
|
101
|
+
}
|
|
102
|
+
}
|
|
@@ -3,22 +3,23 @@ import { hbs } from 'ember-cli-htmlbars';
|
|
|
3
3
|
export const Template = (args) => {
|
|
4
4
|
return {
|
|
5
5
|
template: hbs`
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
6
|
+
<PixModal @showModal={{showModal}} @title={{this.title}} @onCloseButtonClick={{fn (mut showModal) (not showModal)}} >
|
|
7
|
+
<:content>
|
|
8
|
+
<p>
|
|
9
|
+
Une fenêtre modale est, dans une interface graphique, une fenêtre qui prend le contrôle total du clavier et
|
|
10
|
+
de l'écran. Elle est en général associée à une question à laquelle il est impératif que l'utilisateur
|
|
11
|
+
réponde avant de poursuivre, ou de modifier quoi que ce soit. La fenêtre modale a pour propos : d'obtenir
|
|
12
|
+
des informations de l'utilisateur (ces informations sont nécessaires pour réaliser une opération) ; de
|
|
13
|
+
fournir une information à l'utilisateur (ce dernier doit en prendre connaissance avant de pouvoir continuer
|
|
14
|
+
à utiliser l'application).
|
|
15
|
+
</p>
|
|
16
|
+
</:content>
|
|
17
|
+
<:footer>
|
|
18
|
+
<PixButton @backgroundColor="transparent-light" @isBorderVisible="true" @triggerAction={{fn (mut showModal) (not showModal)}}>Annuler</PixButton>
|
|
19
|
+
<PixButton @triggerAction={{fn (mut showModal) (not showModal)}}>Valider</PixButton>
|
|
20
|
+
</:footer>
|
|
21
|
+
</PixModal>
|
|
22
|
+
<PixButton @triggerAction={{fn (mut showModal) (not showModal)}}>Ouvrir la modale</PixButton>
|
|
22
23
|
`,
|
|
23
24
|
context: args,
|
|
24
25
|
};
|
|
@@ -26,10 +27,9 @@ export const Template = (args) => {
|
|
|
26
27
|
|
|
27
28
|
export const Default = Template.bind({});
|
|
28
29
|
Default.args = {
|
|
30
|
+
showModal: true,
|
|
29
31
|
title: "Qu'est-ce qu'une modale ?",
|
|
30
|
-
onCloseButtonClick: () => {
|
|
31
|
-
alert('Action : fermer modale');
|
|
32
|
-
},
|
|
32
|
+
onCloseButtonClick: () => {},
|
|
33
33
|
};
|
|
34
34
|
|
|
35
35
|
export const argTypes = {
|
|
@@ -45,4 +45,14 @@ export const argTypes = {
|
|
|
45
45
|
type: { name: 'function', required: true },
|
|
46
46
|
defaultValue: null,
|
|
47
47
|
},
|
|
48
|
+
showModal: {
|
|
49
|
+
name: 'showModal',
|
|
50
|
+
description: "Gérer l'ouverture de la modale",
|
|
51
|
+
type: { name: 'boolean', required: false },
|
|
52
|
+
control: { type: 'boolean' },
|
|
53
|
+
table: {
|
|
54
|
+
type: { summary: 'boolean' },
|
|
55
|
+
defaultValue: { summary: false },
|
|
56
|
+
},
|
|
57
|
+
},
|
|
48
58
|
};
|
|
@@ -3,7 +3,6 @@ import { hbs } from 'ember-cli-htmlbars';
|
|
|
3
3
|
export const Template = (args) => {
|
|
4
4
|
return {
|
|
5
5
|
template: hbs`
|
|
6
|
-
<PixButton @triggerAction={{fn (mut showSidebar) (not showSidebar)}}>Ouvrir la sidebar</PixButton>
|
|
7
6
|
<PixSidebar @showSidebar={{showSidebar}} @title={{title}} @onClose={{fn (mut showSidebar) (not showSidebar)}}>
|
|
8
7
|
<:content>
|
|
9
8
|
<p>
|
|
@@ -18,6 +17,7 @@ export const Template = (args) => {
|
|
|
18
17
|
</div>
|
|
19
18
|
</:footer>
|
|
20
19
|
</PixSidebar>
|
|
20
|
+
<PixButton @triggerAction={{fn (mut showSidebar) (not showSidebar)}}>Ouvrir la sidebar</PixButton>
|
|
21
21
|
`,
|
|
22
22
|
context: args,
|
|
23
23
|
};
|