@brightspace-ui/core 3.66.2 → 3.68.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.
@@ -2,6 +2,7 @@ import { css, html, LitElement } from 'lit';
|
|
2
2
|
|
3
3
|
/**
|
4
4
|
* A button container component for button toggles.
|
5
|
+
* @fires d2l-button-toggle-before-change - Dispatched before pressed state is updated. Can be canceled to allow the consumer to handle toggling pressed state. This is useful if something needs to happen prior to the pressed state being toggled.
|
5
6
|
*/
|
6
7
|
class ButtonToggle extends LitElement {
|
7
8
|
|
@@ -79,9 +80,16 @@ class ButtonToggle extends LitElement {
|
|
79
80
|
}
|
80
81
|
|
81
82
|
async _handleClick(pressed) {
|
82
|
-
|
83
|
-
|
84
|
-
|
83
|
+
const beforeToggleEvent = new CustomEvent('d2l-button-toggle-before-change', {
|
84
|
+
detail: {
|
85
|
+
update: (newPressed) => this._updatePressedState(newPressed)
|
86
|
+
},
|
87
|
+
cancelable: true
|
88
|
+
});
|
89
|
+
this.dispatchEvent(beforeToggleEvent);
|
90
|
+
if (beforeToggleEvent.defaultPrevented) return;
|
91
|
+
|
92
|
+
this._updatePressedState(pressed);
|
85
93
|
}
|
86
94
|
|
87
95
|
_handleNotPressedClick() {
|
@@ -92,6 +100,12 @@ class ButtonToggle extends LitElement {
|
|
92
100
|
this._handleClick(false);
|
93
101
|
}
|
94
102
|
|
103
|
+
async _updatePressedState(newPressed) {
|
104
|
+
this.pressed = newPressed;
|
105
|
+
await this.updateComplete;
|
106
|
+
this.focus();
|
107
|
+
}
|
108
|
+
|
95
109
|
}
|
96
110
|
|
97
111
|
customElements.define('d2l-button-toggle', ButtonToggle);
|
@@ -54,6 +54,26 @@
|
|
54
54
|
</template>
|
55
55
|
</d2l-demo-snippet>
|
56
56
|
|
57
|
+
<h2>Toggle Button (with consumer specifying when to toggle)</h2>
|
58
|
+
|
59
|
+
<d2l-demo-snippet>
|
60
|
+
<template>
|
61
|
+
<d2l-button-toggle id="toggle-button-icon-promise-delay">
|
62
|
+
<d2l-button-icon slot="not-pressed" icon="tier1:pin-hollow" text="Unpinned, click to pin."></d2l-button-icon>
|
63
|
+
<d2l-button-icon slot="pressed" icon="tier1:pin-filled" text="Pinned, click to unpin."></d2l-button-icon>
|
64
|
+
</d2l-button-toggle>
|
65
|
+
<script>
|
66
|
+
document.querySelector('#toggle-button-icon-promise-delay').addEventListener('d2l-button-toggle-before-change', e => {
|
67
|
+
e.preventDefault();
|
68
|
+
setTimeout(() => {
|
69
|
+
e.detail.update(!e.target.pressed);
|
70
|
+
}, 2000);
|
71
|
+
});
|
72
|
+
document.querySelector('#toggle-button-icon-promise-delay').addEventListener('d2l-button-toggle-change', e => console.log(e));
|
73
|
+
</script>
|
74
|
+
</template>
|
75
|
+
</d2l-demo-snippet>
|
76
|
+
|
57
77
|
</d2l-demo-page>
|
58
78
|
|
59
79
|
</body>
|
@@ -26,3 +26,7 @@ The `d2l-more-less` element can be used to minimize the display of long content,
|
|
26
26
|
| `height` | String, default: `'4em'` | Maximum height of the content when in "less" mode. The `d2l-more-less` element itself will take up additional vertical space for the fading effect as well as the more/less button itself. |
|
27
27
|
| `inactive` | Boolean | Whether the component is active or inactive |
|
28
28
|
<!-- docs: end hidden content -->
|
29
|
+
|
30
|
+
## Accessibility
|
31
|
+
|
32
|
+
The implementation of the `d2l-more-less` component follows the [W3C Disclosure (Show/Hide) Pattern](https://www.w3.org/WAI/ARIA/apg/patterns/disclosure/). It is worth noting that the content that is visually hidden is not actually hidden from screen reader users since those users can interrupt the screen reader if they do not want to continue listening to the content.
|
package/custom-elements.json
CHANGED
@@ -739,6 +739,10 @@
|
|
739
739
|
}
|
740
740
|
],
|
741
741
|
"events": [
|
742
|
+
{
|
743
|
+
"name": "d2l-button-toggle-before-change",
|
744
|
+
"description": "Dispatched before pressed state is updated. Can be canceled to allow the consumer to handle toggling pressed state. This is useful if something needs to happen prior to the pressed state being toggled."
|
745
|
+
},
|
742
746
|
{
|
743
747
|
"name": "d2l-button-toggle-change",
|
744
748
|
"description": "Dispatched when the pressed state changes"
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@brightspace-ui/core",
|
3
|
-
"version": "3.
|
3
|
+
"version": "3.68.0",
|
4
4
|
"description": "A collection of accessible, free, open-source web components for building Brightspace applications",
|
5
5
|
"type": "module",
|
6
6
|
"repository": "https://github.com/BrightspaceUI/core.git",
|