@nectary/components 5.58.0 → 5.59.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/bundle.js +60 -38
- package/package.json +1 -1
- package/toggle/index.d.ts +1 -0
- package/toggle/index.js +23 -9
- package/toggle/types.d.ts +3 -1
- package/utils/dom.js +38 -30
package/bundle.js
CHANGED
|
@@ -175,28 +175,42 @@ const composedContains = (container, node) => {
|
|
|
175
175
|
const isAttrEqual = (oldVal, newVal) => {
|
|
176
176
|
return oldVal === newVal || newVal === null && oldVal === "false" || newVal === "" && oldVal === "true";
|
|
177
177
|
};
|
|
178
|
+
const isScrollableOverflow = (value) => {
|
|
179
|
+
return value === "auto" || value === "scroll";
|
|
180
|
+
};
|
|
181
|
+
const isScrollableElement = (element) => {
|
|
182
|
+
if (element.scrollHeight <= element.clientHeight && element.scrollWidth <= element.clientWidth) {
|
|
183
|
+
return false;
|
|
184
|
+
}
|
|
185
|
+
const style = getComputedStyle(element);
|
|
186
|
+
return isScrollableOverflow(style.overflow) || isScrollableOverflow(style.overflowY) || isScrollableOverflow(style.overflowX);
|
|
187
|
+
};
|
|
188
|
+
const nextFlatTreeAncestor = (element) => {
|
|
189
|
+
const slot = element.assignedSlot;
|
|
190
|
+
if (slot != null) {
|
|
191
|
+
return slot;
|
|
192
|
+
}
|
|
193
|
+
const parent = element.parentElement;
|
|
194
|
+
if (parent != null) {
|
|
195
|
+
return parent;
|
|
196
|
+
}
|
|
197
|
+
const root = element.getRootNode();
|
|
198
|
+
if (root instanceof ShadowRoot && root.host instanceof HTMLElement) {
|
|
199
|
+
return root.host;
|
|
200
|
+
}
|
|
201
|
+
return null;
|
|
202
|
+
};
|
|
178
203
|
const getScrollableParents = (node) => {
|
|
179
204
|
const scrollableParents = [];
|
|
180
205
|
if (node == null) {
|
|
181
206
|
return scrollableParents;
|
|
182
207
|
}
|
|
183
|
-
let current = node
|
|
208
|
+
let current = node;
|
|
184
209
|
while (current != null) {
|
|
185
|
-
|
|
186
|
-
if ((current.scrollHeight > current.clientHeight || current.scrollWidth > current.clientWidth) && (computedStyle.overflow === "auto" || computedStyle.overflow === "scroll" || computedStyle.overflowY === "auto" || computedStyle.overflowY === "scroll" || computedStyle.overflowX === "auto" || computedStyle.overflowX === "scroll")) {
|
|
210
|
+
if (current !== node && isScrollableElement(current)) {
|
|
187
211
|
scrollableParents.push(current);
|
|
188
212
|
}
|
|
189
|
-
|
|
190
|
-
if (parent != null) {
|
|
191
|
-
current = parent;
|
|
192
|
-
continue;
|
|
193
|
-
}
|
|
194
|
-
const root = current.getRootNode();
|
|
195
|
-
if (root instanceof ShadowRoot && root.host instanceof HTMLElement) {
|
|
196
|
-
current = root.host;
|
|
197
|
-
continue;
|
|
198
|
-
}
|
|
199
|
-
break;
|
|
213
|
+
current = nextFlatTreeAncestor(current);
|
|
200
214
|
}
|
|
201
215
|
scrollableParents.push(document);
|
|
202
216
|
return scrollableParents;
|
|
@@ -209,33 +223,27 @@ const createScopedElement = (anchor, tag) => {
|
|
|
209
223
|
}
|
|
210
224
|
return document.createElement(tag);
|
|
211
225
|
};
|
|
226
|
+
const establishesFixedContainingBlock = (contain) => {
|
|
227
|
+
return contain.split(/\s+/).some((value) => {
|
|
228
|
+
return value === "layout" || value === "paint" || value === "content" || value === "strict";
|
|
229
|
+
});
|
|
230
|
+
};
|
|
212
231
|
const isTransformedElement = (element) => {
|
|
213
232
|
if (element == null) {
|
|
214
233
|
return false;
|
|
215
234
|
}
|
|
216
235
|
const style = getComputedStyle(element);
|
|
217
236
|
const backdropFilter = style.getPropertyValue("backdrop-filter");
|
|
218
|
-
|
|
237
|
+
const contentVisibility = style.getPropertyValue("content-visibility");
|
|
238
|
+
return style.transform !== "none" || style.perspective !== "none" || style.filter !== "none" || backdropFilter !== "" && backdropFilter !== "none" || establishesFixedContainingBlock(style.getPropertyValue("contain")) || contentVisibility === "auto" || contentVisibility === "hidden";
|
|
219
239
|
};
|
|
220
240
|
const getTransformedAncestor = (node) => {
|
|
221
241
|
let current = node;
|
|
222
242
|
while (current != null) {
|
|
223
|
-
if (current !== node) {
|
|
224
|
-
|
|
225
|
-
return current;
|
|
226
|
-
}
|
|
227
|
-
}
|
|
228
|
-
const parent = current.parentElement;
|
|
229
|
-
if (parent != null) {
|
|
230
|
-
current = parent;
|
|
231
|
-
continue;
|
|
232
|
-
}
|
|
233
|
-
const root = current.getRootNode();
|
|
234
|
-
if (root instanceof ShadowRoot && root.host instanceof HTMLElement) {
|
|
235
|
-
current = root.host;
|
|
236
|
-
continue;
|
|
243
|
+
if (current !== node && isTransformedElement(current)) {
|
|
244
|
+
return current;
|
|
237
245
|
}
|
|
238
|
-
|
|
246
|
+
current = nextFlatTreeAncestor(current);
|
|
239
247
|
}
|
|
240
248
|
return null;
|
|
241
249
|
};
|
|
@@ -18896,16 +18904,19 @@ class ToastManager extends NectaryElement {
|
|
|
18896
18904
|
};
|
|
18897
18905
|
}
|
|
18898
18906
|
defineCustomElement("sinch-toast-manager", ToastManager);
|
|
18899
|
-
const templateHTML = '<style>:host{display:inline-block;vertical-align:middle;outline:0}#wrapper{position:relative;display:flex;flex-direction:row;gap:8px;width:100%;height:var(--sinch-local-size);cursor:pointer;user-select:none;--sinch-local-size:20px}:host([small]) #wrapper{--sinch-local-size:16px}:host([disabled]) #wrapper{cursor:initial}#knob-container{position:relative;width:40px;height:var(--sinch-local-size);border-radius:calc(var(--sinch-local-size) * .5);background-color:var(--sinch-comp-toggle-color-default-background-initial);pointer-events:none;transition:background-color .15s ease-in-out}:host([small]) #knob-container{width:32px;height:var(--sinch-local-size)}:host([checked]) #knob-container{background-color:var(--sinch-comp-toggle-color-checked-background-initial)}:host([disabled]) #knob-container{background-color:var(--sinch-comp-toggle-color-disabled-background-initial)}:host([checked][disabled]) #knob-container{background-color:var(--sinch-comp-toggle-color-checked-disabled-background-initial)}#knob{position:relative;width:16px;height:16px;left:2px;top:2px;border-radius:50%;background-color:var(--sinch-comp-toggle-color-default-knob-background-initial);box-shadow:var(--sinch-comp-toggle-shadow-knob-default);transform:translateX(0);transition:transform .15s ease-in-out;will-change:transform}:host([small]) #knob{width:12px;height:12px}:host([disabled]) #knob-container>#knob{box-shadow:var(--sinch-comp-toggle-shadow-knob-disabled)}:host([checked]) #knob-container>#knob{transform:translateX(20px)}:host([small][checked]) #knob-container>#knob{transform:translateX(16px)}#knob::after,#knob::before{font:var(--sinch-comp-toggle-font-size-m-inside-text);color:var(--sinch-comp-toggle-color-default-text-inside-initial);text-transform:uppercase;position:absolute;top:0;padding:0 1px;opacity:0;transition:opacity .15s ease-in-out;user-select:none}#knob::before{content:"on";right:100%}#knob::after{content:"off";left:100%}:host([labeled]:not([small]):not([checked])) #knob::after{opacity:1}:host([labeled]:not([small])[checked]) #knob::before{opacity:1}@media (prefers-reduced-motion){#knob,#knob-container,#knob::after,#knob::before{transition:none}}#outline{display:none;position:absolute;left:-3px;top:-3px;right:-3px;bottom:-3px;border:2px solid var(--sinch-comp-toggle-color-default-outline-focus);border-radius:17px;pointer-events:none}:host(:focus-visible) #outline{display:block}#label{flex:1;min-width:0;align-self:center;overflow:hidden;white-space:nowrap;text-overflow:ellipsis;font:var(--sinch-comp-toggle-font-size-m-label);color:var(--sinch-comp-toggle-color-default-label-initial)}#label:empty{display:none}:host([small]) #label{font:var(--sinch-comp-toggle-font-size-s-label)}:host([disabled]) #label{color:var(--sinch-comp-toggle-color-disabled-label-initial)}</style><div id="wrapper"><div id="knob-container"><div id="outline"></div><div id="knob"></div></div><span id="label"></span></div>';
|
|
18907
|
+
const templateHTML = '<style>:host{display:inline-block;vertical-align:middle;outline:0}#wrapper{position:relative;display:flex;flex-direction:row;gap:8px;width:100%;height:var(--sinch-local-size);cursor:pointer;user-select:none;--sinch-local-size:20px}:host([small]) #wrapper{--sinch-local-size:16px}:host([disabled]) #wrapper{cursor:initial}#knob-container{position:relative;width:40px;height:var(--sinch-local-size);border-radius:calc(var(--sinch-local-size) * .5);background-color:var(--sinch-comp-toggle-color-default-background-initial);pointer-events:none;transition:background-color .15s ease-in-out}:host([small]) #knob-container{width:32px;height:var(--sinch-local-size)}:host([checked]) #knob-container{background-color:var(--sinch-comp-toggle-color-checked-background-initial)}:host([disabled]) #knob-container{background-color:var(--sinch-comp-toggle-color-disabled-background-initial)}:host([checked][disabled]) #knob-container{background-color:var(--sinch-comp-toggle-color-checked-disabled-background-initial)}#knob{position:relative;width:16px;height:16px;left:2px;top:2px;border-radius:50%;background-color:var(--sinch-comp-toggle-color-default-knob-background-initial);box-shadow:var(--sinch-comp-toggle-shadow-knob-default);transform:translateX(0);transition:transform .15s ease-in-out;will-change:transform}:host([small]) #knob{width:12px;height:12px}:host([disabled]) #knob-container>#knob{box-shadow:var(--sinch-comp-toggle-shadow-knob-disabled)}:host([checked]) #knob-container>#knob{transform:translateX(20px)}:host([small][checked]) #knob-container>#knob{transform:translateX(16px)}#knob::after,#knob::before{font:var(--sinch-comp-toggle-font-size-m-inside-text);color:var(--sinch-comp-toggle-color-default-text-inside-initial);text-transform:uppercase;position:absolute;top:0;padding:0 1px;opacity:0;transition:opacity .15s ease-in-out;user-select:none}#knob::before{content:"on";content:"on"/"";right:100%}#knob::after{content:"off";content:"off"/"";left:100%}:host([labeled]:not([small]):not([checked])) #knob::after{opacity:1}:host([labeled]:not([small])[checked]) #knob::before{opacity:1}@media (prefers-reduced-motion){#knob,#knob-container,#knob::after,#knob::before{transition:none}}#outline{display:none;position:absolute;left:-3px;top:-3px;right:-3px;bottom:-3px;border:2px solid var(--sinch-comp-toggle-color-default-outline-focus);border-radius:17px;pointer-events:none}:host(:focus-visible) #outline{display:block}#label{flex:1;min-width:0;align-self:center;overflow:hidden;white-space:nowrap;text-overflow:ellipsis;font:var(--sinch-comp-toggle-font-size-m-label);color:var(--sinch-comp-toggle-color-default-label-initial)}#label:empty{display:none}:host([small]) #label{font:var(--sinch-comp-toggle-font-size-s-label)}:host([disabled]) #label{color:var(--sinch-comp-toggle-color-disabled-label-initial)}</style><div id="wrapper"><div id="knob-container"><div id="outline"></div><div id="knob"></div></div><span id="label"></span></div>';
|
|
18900
18908
|
const template = document.createElement("template");
|
|
18901
18909
|
template.innerHTML = templateHTML;
|
|
18902
18910
|
class Toggle extends NectaryElement {
|
|
18903
18911
|
#$label;
|
|
18904
18912
|
#controller = null;
|
|
18913
|
+
#internals;
|
|
18914
|
+
static formAssociated = true;
|
|
18905
18915
|
constructor() {
|
|
18906
18916
|
super();
|
|
18907
18917
|
const shadowRoot = this.attachShadow();
|
|
18908
18918
|
shadowRoot.appendChild(template.content.cloneNode(true));
|
|
18919
|
+
this.#internals = this.attachInternals();
|
|
18909
18920
|
this.#$label = shadowRoot.querySelector("#label");
|
|
18910
18921
|
}
|
|
18911
18922
|
connectedCallback() {
|
|
@@ -18913,6 +18924,9 @@ class Toggle extends NectaryElement {
|
|
|
18913
18924
|
const { signal } = this.#controller;
|
|
18914
18925
|
const options = { signal };
|
|
18915
18926
|
this.setAttribute("role", "checkbox");
|
|
18927
|
+
this.#internals.role = "checkbox";
|
|
18928
|
+
this.#syncChecked();
|
|
18929
|
+
this.#syncDisabled();
|
|
18916
18930
|
this.addEventListener("click", this.#onClick, options);
|
|
18917
18931
|
this.addEventListener("keydown", this.#onKeydown, options);
|
|
18918
18932
|
this.addEventListener("focus", this.#onFocus, options);
|
|
@@ -18945,16 +18959,11 @@ class Toggle extends NectaryElement {
|
|
|
18945
18959
|
break;
|
|
18946
18960
|
}
|
|
18947
18961
|
case "checked": {
|
|
18948
|
-
|
|
18949
|
-
updateExplicitBooleanAttribute(this, "aria-checked", isChecked);
|
|
18950
|
-
updateBooleanAttribute(this, name, isChecked);
|
|
18962
|
+
this.#syncChecked();
|
|
18951
18963
|
break;
|
|
18952
18964
|
}
|
|
18953
18965
|
case "disabled": {
|
|
18954
|
-
|
|
18955
|
-
this.#updateTabIndex();
|
|
18956
|
-
updateExplicitBooleanAttribute(this, "aria-disabled", isDisabled);
|
|
18957
|
-
updateBooleanAttribute(this, name, isDisabled);
|
|
18966
|
+
this.#syncDisabled();
|
|
18958
18967
|
break;
|
|
18959
18968
|
}
|
|
18960
18969
|
case "small":
|
|
@@ -19014,6 +19023,19 @@ class Toggle extends NectaryElement {
|
|
|
19014
19023
|
}
|
|
19015
19024
|
}
|
|
19016
19025
|
};
|
|
19026
|
+
#syncChecked() {
|
|
19027
|
+
const isChecked = this.checked;
|
|
19028
|
+
updateExplicitBooleanAttribute(this, "aria-checked", isChecked);
|
|
19029
|
+
this.#internals.ariaChecked = isChecked.toString();
|
|
19030
|
+
updateBooleanAttribute(this, "checked", isChecked);
|
|
19031
|
+
}
|
|
19032
|
+
#syncDisabled() {
|
|
19033
|
+
const isDisabled = this.disabled;
|
|
19034
|
+
this.#updateTabIndex();
|
|
19035
|
+
updateExplicitBooleanAttribute(this, "aria-disabled", isDisabled);
|
|
19036
|
+
this.#internals.ariaDisabled = isDisabled.toString();
|
|
19037
|
+
updateBooleanAttribute(this, "disabled", isDisabled);
|
|
19038
|
+
}
|
|
19017
19039
|
#updateTabIndex() {
|
|
19018
19040
|
this.tabIndex = this.disabled ? -1 : 0;
|
|
19019
19041
|
}
|
package/package.json
CHANGED
package/toggle/index.d.ts
CHANGED
package/toggle/index.js
CHANGED
|
@@ -1,16 +1,19 @@
|
|
|
1
|
-
import { isAttrEqual, updateBooleanAttribute, isAttrTrue,
|
|
1
|
+
import { isAttrEqual, updateBooleanAttribute, isAttrTrue, getBooleanAttribute, updateAttribute, getAttribute, updateExplicitBooleanAttribute } from "../utils/dom.js";
|
|
2
2
|
import { defineCustomElement, NectaryElement } from "../utils/element.js";
|
|
3
3
|
import { getReactEventHandler } from "../utils/get-react-event-handler.js";
|
|
4
|
-
const templateHTML = '<style>:host{display:inline-block;vertical-align:middle;outline:0}#wrapper{position:relative;display:flex;flex-direction:row;gap:8px;width:100%;height:var(--sinch-local-size);cursor:pointer;user-select:none;--sinch-local-size:20px}:host([small]) #wrapper{--sinch-local-size:16px}:host([disabled]) #wrapper{cursor:initial}#knob-container{position:relative;width:40px;height:var(--sinch-local-size);border-radius:calc(var(--sinch-local-size) * .5);background-color:var(--sinch-comp-toggle-color-default-background-initial);pointer-events:none;transition:background-color .15s ease-in-out}:host([small]) #knob-container{width:32px;height:var(--sinch-local-size)}:host([checked]) #knob-container{background-color:var(--sinch-comp-toggle-color-checked-background-initial)}:host([disabled]) #knob-container{background-color:var(--sinch-comp-toggle-color-disabled-background-initial)}:host([checked][disabled]) #knob-container{background-color:var(--sinch-comp-toggle-color-checked-disabled-background-initial)}#knob{position:relative;width:16px;height:16px;left:2px;top:2px;border-radius:50%;background-color:var(--sinch-comp-toggle-color-default-knob-background-initial);box-shadow:var(--sinch-comp-toggle-shadow-knob-default);transform:translateX(0);transition:transform .15s ease-in-out;will-change:transform}:host([small]) #knob{width:12px;height:12px}:host([disabled]) #knob-container>#knob{box-shadow:var(--sinch-comp-toggle-shadow-knob-disabled)}:host([checked]) #knob-container>#knob{transform:translateX(20px)}:host([small][checked]) #knob-container>#knob{transform:translateX(16px)}#knob::after,#knob::before{font:var(--sinch-comp-toggle-font-size-m-inside-text);color:var(--sinch-comp-toggle-color-default-text-inside-initial);text-transform:uppercase;position:absolute;top:0;padding:0 1px;opacity:0;transition:opacity .15s ease-in-out;user-select:none}#knob::before{content:"on";right:100%}#knob::after{content:"off";left:100%}:host([labeled]:not([small]):not([checked])) #knob::after{opacity:1}:host([labeled]:not([small])[checked]) #knob::before{opacity:1}@media (prefers-reduced-motion){#knob,#knob-container,#knob::after,#knob::before{transition:none}}#outline{display:none;position:absolute;left:-3px;top:-3px;right:-3px;bottom:-3px;border:2px solid var(--sinch-comp-toggle-color-default-outline-focus);border-radius:17px;pointer-events:none}:host(:focus-visible) #outline{display:block}#label{flex:1;min-width:0;align-self:center;overflow:hidden;white-space:nowrap;text-overflow:ellipsis;font:var(--sinch-comp-toggle-font-size-m-label);color:var(--sinch-comp-toggle-color-default-label-initial)}#label:empty{display:none}:host([small]) #label{font:var(--sinch-comp-toggle-font-size-s-label)}:host([disabled]) #label{color:var(--sinch-comp-toggle-color-disabled-label-initial)}</style><div id="wrapper"><div id="knob-container"><div id="outline"></div><div id="knob"></div></div><span id="label"></span></div>';
|
|
4
|
+
const templateHTML = '<style>:host{display:inline-block;vertical-align:middle;outline:0}#wrapper{position:relative;display:flex;flex-direction:row;gap:8px;width:100%;height:var(--sinch-local-size);cursor:pointer;user-select:none;--sinch-local-size:20px}:host([small]) #wrapper{--sinch-local-size:16px}:host([disabled]) #wrapper{cursor:initial}#knob-container{position:relative;width:40px;height:var(--sinch-local-size);border-radius:calc(var(--sinch-local-size) * .5);background-color:var(--sinch-comp-toggle-color-default-background-initial);pointer-events:none;transition:background-color .15s ease-in-out}:host([small]) #knob-container{width:32px;height:var(--sinch-local-size)}:host([checked]) #knob-container{background-color:var(--sinch-comp-toggle-color-checked-background-initial)}:host([disabled]) #knob-container{background-color:var(--sinch-comp-toggle-color-disabled-background-initial)}:host([checked][disabled]) #knob-container{background-color:var(--sinch-comp-toggle-color-checked-disabled-background-initial)}#knob{position:relative;width:16px;height:16px;left:2px;top:2px;border-radius:50%;background-color:var(--sinch-comp-toggle-color-default-knob-background-initial);box-shadow:var(--sinch-comp-toggle-shadow-knob-default);transform:translateX(0);transition:transform .15s ease-in-out;will-change:transform}:host([small]) #knob{width:12px;height:12px}:host([disabled]) #knob-container>#knob{box-shadow:var(--sinch-comp-toggle-shadow-knob-disabled)}:host([checked]) #knob-container>#knob{transform:translateX(20px)}:host([small][checked]) #knob-container>#knob{transform:translateX(16px)}#knob::after,#knob::before{font:var(--sinch-comp-toggle-font-size-m-inside-text);color:var(--sinch-comp-toggle-color-default-text-inside-initial);text-transform:uppercase;position:absolute;top:0;padding:0 1px;opacity:0;transition:opacity .15s ease-in-out;user-select:none}#knob::before{content:"on";content:"on"/"";right:100%}#knob::after{content:"off";content:"off"/"";left:100%}:host([labeled]:not([small]):not([checked])) #knob::after{opacity:1}:host([labeled]:not([small])[checked]) #knob::before{opacity:1}@media (prefers-reduced-motion){#knob,#knob-container,#knob::after,#knob::before{transition:none}}#outline{display:none;position:absolute;left:-3px;top:-3px;right:-3px;bottom:-3px;border:2px solid var(--sinch-comp-toggle-color-default-outline-focus);border-radius:17px;pointer-events:none}:host(:focus-visible) #outline{display:block}#label{flex:1;min-width:0;align-self:center;overflow:hidden;white-space:nowrap;text-overflow:ellipsis;font:var(--sinch-comp-toggle-font-size-m-label);color:var(--sinch-comp-toggle-color-default-label-initial)}#label:empty{display:none}:host([small]) #label{font:var(--sinch-comp-toggle-font-size-s-label)}:host([disabled]) #label{color:var(--sinch-comp-toggle-color-disabled-label-initial)}</style><div id="wrapper"><div id="knob-container"><div id="outline"></div><div id="knob"></div></div><span id="label"></span></div>';
|
|
5
5
|
const template = document.createElement("template");
|
|
6
6
|
template.innerHTML = templateHTML;
|
|
7
7
|
class Toggle extends NectaryElement {
|
|
8
8
|
#$label;
|
|
9
9
|
#controller = null;
|
|
10
|
+
#internals;
|
|
11
|
+
static formAssociated = true;
|
|
10
12
|
constructor() {
|
|
11
13
|
super();
|
|
12
14
|
const shadowRoot = this.attachShadow();
|
|
13
15
|
shadowRoot.appendChild(template.content.cloneNode(true));
|
|
16
|
+
this.#internals = this.attachInternals();
|
|
14
17
|
this.#$label = shadowRoot.querySelector("#label");
|
|
15
18
|
}
|
|
16
19
|
connectedCallback() {
|
|
@@ -18,6 +21,9 @@ class Toggle extends NectaryElement {
|
|
|
18
21
|
const { signal } = this.#controller;
|
|
19
22
|
const options = { signal };
|
|
20
23
|
this.setAttribute("role", "checkbox");
|
|
24
|
+
this.#internals.role = "checkbox";
|
|
25
|
+
this.#syncChecked();
|
|
26
|
+
this.#syncDisabled();
|
|
21
27
|
this.addEventListener("click", this.#onClick, options);
|
|
22
28
|
this.addEventListener("keydown", this.#onKeydown, options);
|
|
23
29
|
this.addEventListener("focus", this.#onFocus, options);
|
|
@@ -50,16 +56,11 @@ class Toggle extends NectaryElement {
|
|
|
50
56
|
break;
|
|
51
57
|
}
|
|
52
58
|
case "checked": {
|
|
53
|
-
|
|
54
|
-
updateExplicitBooleanAttribute(this, "aria-checked", isChecked);
|
|
55
|
-
updateBooleanAttribute(this, name, isChecked);
|
|
59
|
+
this.#syncChecked();
|
|
56
60
|
break;
|
|
57
61
|
}
|
|
58
62
|
case "disabled": {
|
|
59
|
-
|
|
60
|
-
this.#updateTabIndex();
|
|
61
|
-
updateExplicitBooleanAttribute(this, "aria-disabled", isDisabled);
|
|
62
|
-
updateBooleanAttribute(this, name, isDisabled);
|
|
63
|
+
this.#syncDisabled();
|
|
63
64
|
break;
|
|
64
65
|
}
|
|
65
66
|
case "small":
|
|
@@ -119,6 +120,19 @@ class Toggle extends NectaryElement {
|
|
|
119
120
|
}
|
|
120
121
|
}
|
|
121
122
|
};
|
|
123
|
+
#syncChecked() {
|
|
124
|
+
const isChecked = this.checked;
|
|
125
|
+
updateExplicitBooleanAttribute(this, "aria-checked", isChecked);
|
|
126
|
+
this.#internals.ariaChecked = isChecked.toString();
|
|
127
|
+
updateBooleanAttribute(this, "checked", isChecked);
|
|
128
|
+
}
|
|
129
|
+
#syncDisabled() {
|
|
130
|
+
const isDisabled = this.disabled;
|
|
131
|
+
this.#updateTabIndex();
|
|
132
|
+
updateExplicitBooleanAttribute(this, "aria-disabled", isDisabled);
|
|
133
|
+
this.#internals.ariaDisabled = isDisabled.toString();
|
|
134
|
+
updateBooleanAttribute(this, "disabled", isDisabled);
|
|
135
|
+
}
|
|
122
136
|
#updateTabIndex() {
|
|
123
137
|
this.tabIndex = this.disabled ? -1 : 0;
|
|
124
138
|
}
|
package/toggle/types.d.ts
CHANGED
|
@@ -5,7 +5,9 @@ export type TSinchToggleProps = {
|
|
|
5
5
|
labeled?: boolean;
|
|
6
6
|
disabled?: boolean;
|
|
7
7
|
text?: string;
|
|
8
|
-
|
|
8
|
+
/** Id a label's for attribute can point at */
|
|
9
|
+
id?: string;
|
|
10
|
+
'aria-label'?: string;
|
|
9
11
|
};
|
|
10
12
|
export type TSinchToggleEvents = {
|
|
11
13
|
'-change'?: (e: CustomEvent<boolean>) => void;
|
package/utils/dom.js
CHANGED
|
@@ -185,28 +185,42 @@ const composedContains = (container, node) => {
|
|
|
185
185
|
const isAttrEqual = (oldVal, newVal) => {
|
|
186
186
|
return oldVal === newVal || newVal === null && oldVal === "false" || newVal === "" && oldVal === "true";
|
|
187
187
|
};
|
|
188
|
+
const isScrollableOverflow = (value) => {
|
|
189
|
+
return value === "auto" || value === "scroll";
|
|
190
|
+
};
|
|
191
|
+
const isScrollableElement = (element) => {
|
|
192
|
+
if (element.scrollHeight <= element.clientHeight && element.scrollWidth <= element.clientWidth) {
|
|
193
|
+
return false;
|
|
194
|
+
}
|
|
195
|
+
const style = getComputedStyle(element);
|
|
196
|
+
return isScrollableOverflow(style.overflow) || isScrollableOverflow(style.overflowY) || isScrollableOverflow(style.overflowX);
|
|
197
|
+
};
|
|
198
|
+
const nextFlatTreeAncestor = (element) => {
|
|
199
|
+
const slot = element.assignedSlot;
|
|
200
|
+
if (slot != null) {
|
|
201
|
+
return slot;
|
|
202
|
+
}
|
|
203
|
+
const parent = element.parentElement;
|
|
204
|
+
if (parent != null) {
|
|
205
|
+
return parent;
|
|
206
|
+
}
|
|
207
|
+
const root = element.getRootNode();
|
|
208
|
+
if (root instanceof ShadowRoot && root.host instanceof HTMLElement) {
|
|
209
|
+
return root.host;
|
|
210
|
+
}
|
|
211
|
+
return null;
|
|
212
|
+
};
|
|
188
213
|
const getScrollableParents = (node) => {
|
|
189
214
|
const scrollableParents = [];
|
|
190
215
|
if (node == null) {
|
|
191
216
|
return scrollableParents;
|
|
192
217
|
}
|
|
193
|
-
let current = node
|
|
218
|
+
let current = node;
|
|
194
219
|
while (current != null) {
|
|
195
|
-
|
|
196
|
-
if ((current.scrollHeight > current.clientHeight || current.scrollWidth > current.clientWidth) && (computedStyle.overflow === "auto" || computedStyle.overflow === "scroll" || computedStyle.overflowY === "auto" || computedStyle.overflowY === "scroll" || computedStyle.overflowX === "auto" || computedStyle.overflowX === "scroll")) {
|
|
220
|
+
if (current !== node && isScrollableElement(current)) {
|
|
197
221
|
scrollableParents.push(current);
|
|
198
222
|
}
|
|
199
|
-
|
|
200
|
-
if (parent != null) {
|
|
201
|
-
current = parent;
|
|
202
|
-
continue;
|
|
203
|
-
}
|
|
204
|
-
const root = current.getRootNode();
|
|
205
|
-
if (root instanceof ShadowRoot && root.host instanceof HTMLElement) {
|
|
206
|
-
current = root.host;
|
|
207
|
-
continue;
|
|
208
|
-
}
|
|
209
|
-
break;
|
|
223
|
+
current = nextFlatTreeAncestor(current);
|
|
210
224
|
}
|
|
211
225
|
scrollableParents.push(document);
|
|
212
226
|
return scrollableParents;
|
|
@@ -219,33 +233,27 @@ const createScopedElement = (anchor, tag) => {
|
|
|
219
233
|
}
|
|
220
234
|
return document.createElement(tag);
|
|
221
235
|
};
|
|
236
|
+
const establishesFixedContainingBlock = (contain) => {
|
|
237
|
+
return contain.split(/\s+/).some((value) => {
|
|
238
|
+
return value === "layout" || value === "paint" || value === "content" || value === "strict";
|
|
239
|
+
});
|
|
240
|
+
};
|
|
222
241
|
const isTransformedElement = (element) => {
|
|
223
242
|
if (element == null) {
|
|
224
243
|
return false;
|
|
225
244
|
}
|
|
226
245
|
const style = getComputedStyle(element);
|
|
227
246
|
const backdropFilter = style.getPropertyValue("backdrop-filter");
|
|
228
|
-
|
|
247
|
+
const contentVisibility = style.getPropertyValue("content-visibility");
|
|
248
|
+
return style.transform !== "none" || style.perspective !== "none" || style.filter !== "none" || backdropFilter !== "" && backdropFilter !== "none" || establishesFixedContainingBlock(style.getPropertyValue("contain")) || contentVisibility === "auto" || contentVisibility === "hidden";
|
|
229
249
|
};
|
|
230
250
|
const getTransformedAncestor = (node) => {
|
|
231
251
|
let current = node;
|
|
232
252
|
while (current != null) {
|
|
233
|
-
if (current !== node) {
|
|
234
|
-
|
|
235
|
-
return current;
|
|
236
|
-
}
|
|
237
|
-
}
|
|
238
|
-
const parent = current.parentElement;
|
|
239
|
-
if (parent != null) {
|
|
240
|
-
current = parent;
|
|
241
|
-
continue;
|
|
242
|
-
}
|
|
243
|
-
const root = current.getRootNode();
|
|
244
|
-
if (root instanceof ShadowRoot && root.host instanceof HTMLElement) {
|
|
245
|
-
current = root.host;
|
|
246
|
-
continue;
|
|
253
|
+
if (current !== node && isTransformedElement(current)) {
|
|
254
|
+
return current;
|
|
247
255
|
}
|
|
248
|
-
|
|
256
|
+
current = nextFlatTreeAncestor(current);
|
|
249
257
|
}
|
|
250
258
|
return null;
|
|
251
259
|
};
|