@oicl/openbridge-webcomponents-full-bundle 2.0.0-next.171 → 2.0.0-next.173
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/openbridge-webcomponents.bundle.js +286 -105
- package/bundle/openbridge-webcomponents.bundle.js.map +1 -1
- package/custom-elements.json +736 -46
- package/dist/automation/automation-button/abstract-automation-button-motorized.d.ts +11 -1
- package/dist/automation/automation-button/abstract-automation-button-motorized.d.ts.map +1 -1
- package/dist/automation/automation-button/abstract-automation-button-motorized.js +14 -4
- package/dist/automation/automation-button/abstract-automation-button-motorized.js.map +1 -1
- package/dist/automation/automation-button/abstract-automation-button-squared.d.ts +25 -1
- package/dist/automation/automation-button/abstract-automation-button-squared.d.ts.map +1 -1
- package/dist/automation/automation-button/abstract-automation-button-squared.js +27 -3
- package/dist/automation/automation-button/abstract-automation-button-squared.js.map +1 -1
- package/dist/automation/automation-button/abstract-automation-button-storybook-helpers.d.ts +12 -0
- package/dist/automation/automation-button/abstract-automation-button-storybook-helpers.d.ts.map +1 -1
- package/dist/automation/automation-button/abstract-automation-button-storybook-helpers.js +8 -0
- package/dist/automation/automation-button/abstract-automation-button-storybook-helpers.js.map +1 -1
- package/dist/automation/bipolar-transistor/bipolar-transistor.js +4 -4
- package/dist/automation/bipolar-transistor/bipolar-transistor.js.map +1 -1
- package/dist/automation/capacitor/capacitor.js +4 -4
- package/dist/automation/capacitor/capacitor.js.map +1 -1
- package/dist/automation/converter/converter.js +4 -4
- package/dist/automation/converter/converter.js.map +1 -1
- package/dist/automation/damper/damper.js +1 -1
- package/dist/automation/damper/damper.js.map +1 -1
- package/dist/automation/diodes/diodes.js +6 -6
- package/dist/automation/diodes/diodes.js.map +1 -1
- package/dist/automation/fan/fan.js +1 -1
- package/dist/automation/fan/fan.js.map +1 -1
- package/dist/automation/filter/filter.js +4 -4
- package/dist/automation/filter/filter.js.map +1 -1
- package/dist/automation/ground/ground.js +3 -3
- package/dist/automation/ground/ground.js.map +1 -1
- package/dist/automation/logic/logic.js +6 -6
- package/dist/automation/logic/logic.js.map +1 -1
- package/dist/automation/mosfet/mosfet.js +8 -8
- package/dist/automation/mosfet/mosfet.js.map +1 -1
- package/dist/automation/motor/motor.js +2 -2
- package/dist/automation/motor/motor.js.map +1 -1
- package/dist/automation/pump/pump.js +2 -2
- package/dist/automation/pump/pump.js.map +1 -1
- package/dist/automation/resistor/resistor.js +5 -5
- package/dist/automation/resistor/resistor.js.map +1 -1
- package/dist/automation/router/router.js +2 -2
- package/dist/automation/router/router.js.map +1 -1
- package/dist/automation/source/source.js +5 -5
- package/dist/automation/source/source.js.map +1 -1
- package/dist/automation/switch/switch.js +4 -4
- package/dist/automation/switch/switch.js.map +1 -1
- package/dist/automation/transformer/transformer.js +2 -2
- package/dist/automation/transformer/transformer.js.map +1 -1
- package/dist/components/accordion-card/accordion-card.css.js +61 -19
- package/dist/components/accordion-card/accordion-card.css.js.map +1 -1
- package/dist/components/accordion-card/accordion-card.d.ts +12 -3
- package/dist/components/accordion-card/accordion-card.d.ts.map +1 -1
- package/dist/components/accordion-card/accordion-card.js +23 -5
- package/dist/components/accordion-card/accordion-card.js.map +1 -1
- package/dist/components/accordion-item/accordion-item.css.js +40 -9
- package/dist/components/accordion-item/accordion-item.css.js.map +1 -1
- package/dist/components/accordion-item/accordion-item.d.ts +14 -5
- package/dist/components/accordion-item/accordion-item.d.ts.map +1 -1
- package/dist/components/accordion-item/accordion-item.js +23 -3
- package/dist/components/accordion-item/accordion-item.js.map +1 -1
- package/dist/internal/focus.d.ts +23 -0
- package/dist/internal/focus.d.ts.map +1 -1
- package/dist/internal/focus.js +38 -1
- package/dist/internal/focus.js.map +1 -1
- package/eslint.config.mjs +56 -0
- package/package.json +1 -1
- package/script/eslint-rules.test.ts +44 -0
- package/src/automation/automation-button/abstract-automation-button-motorized.ts +20 -4
- package/src/automation/automation-button/abstract-automation-button-squared.ts +33 -3
- package/src/automation/automation-button/abstract-automation-button-storybook-helpers.ts +2 -0
- package/src/automation/automation-button/turned-on.spec.ts +64 -0
- package/src/automation/bipolar-transistor/bipolar-transistor.stories.ts +2 -2
- package/src/automation/bipolar-transistor/bipolar-transistor.ts +4 -4
- package/src/automation/capacitor/capacitor.stories.ts +2 -2
- package/src/automation/capacitor/capacitor.ts +4 -4
- package/src/automation/converter/converter.stories.ts +2 -2
- package/src/automation/converter/converter.ts +4 -4
- package/src/automation/damper/damper.stories.ts +2 -2
- package/src/automation/damper/damper.ts +1 -1
- package/src/automation/diodes/diodes.stories.ts +2 -2
- package/src/automation/diodes/diodes.ts +6 -6
- package/src/automation/fan/fan.stories.ts +3 -3
- package/src/automation/fan/fan.ts +1 -1
- package/src/automation/filter/filter.stories.ts +2 -2
- package/src/automation/filter/filter.ts +4 -4
- package/src/automation/ground/ground.stories.ts +2 -2
- package/src/automation/ground/ground.ts +3 -3
- package/src/automation/logic/logic.stories.ts +2 -2
- package/src/automation/logic/logic.ts +6 -6
- package/src/automation/mosfet/mosfet.stories.ts +2 -2
- package/src/automation/mosfet/mosfet.ts +8 -8
- package/src/automation/motor/motor.stories.ts +7 -7
- package/src/automation/motor/motor.ts +2 -2
- package/src/automation/pump/pump.stories.ts +5 -5
- package/src/automation/pump/pump.ts +2 -2
- package/src/automation/resistor/resistor.stories.ts +2 -2
- package/src/automation/resistor/resistor.ts +5 -5
- package/src/automation/router/router.stories.ts +2 -2
- package/src/automation/router/router.ts +2 -2
- package/src/automation/source/source.stories.ts +2 -2
- package/src/automation/source/source.ts +5 -5
- package/src/automation/switch/switch.stories.ts +4 -4
- package/src/automation/switch/switch.ts +4 -4
- package/src/automation/transformer/transformer.stories.ts +2 -2
- package/src/automation/transformer/transformer.ts +2 -2
- package/src/components/accordion-card/accordion-card.css +57 -15
- package/src/components/accordion-card/accordion-card.spec.ts +171 -0
- package/src/components/accordion-card/accordion-card.ts +32 -12
- package/src/components/accordion-item/accordion-item.css +40 -9
- package/src/components/accordion-item/accordion-item.spec.ts +161 -0
- package/src/components/accordion-item/accordion-item.ts +34 -9
- package/src/internal/_test-utils.ts +3 -12
- package/src/internal/focus.ts +45 -0
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { LitElement } from 'lit';
|
|
1
|
+
import { LitElement, PropertyValues } from 'lit';
|
|
2
2
|
import '../../icons/icon-chevron-down-google.js';
|
|
3
3
|
/**
|
|
4
4
|
* `<obc-accordion-item>` – A collapsible section component for toggling the visibility of content panels (commonly known as an accordion item, expandable panel, or disclosure).
|
|
@@ -6,11 +6,10 @@ import '../../icons/icon-chevron-down-google.js';
|
|
|
6
6
|
* Provides a single expandable/collapsible section with a clickable header and an optional content area. Useful for organizing related information in a compact, vertically stacked layout, allowing users to reveal or hide details as needed.
|
|
7
7
|
*
|
|
8
8
|
* ### Features
|
|
9
|
-
* - **Toggleable Expansion:** Click the header to expand or collapse the content area. The
|
|
9
|
+
* - **Toggleable Expansion:** Click the header to expand or collapse the content area. The panel slides open and closed, and the chevron turns with it; `prefers-reduced-motion: reduce` switches instantly instead.
|
|
10
10
|
* - **Disabled State:** Prevents user interaction and visually indicates non-interactivity.
|
|
11
11
|
* - **Customizable Content:** Slot for custom expanded content (`expanded-content`), supporting any HTML or component.
|
|
12
12
|
* - **Optional Divider:** Can display a divider line below the item for visual separation in lists.
|
|
13
|
-
* - **Show/Hide Content Area:** Optionally hide the expanded content area entirely (e.g., for header-only items).
|
|
14
13
|
* - **Accessible:** Uses a button for the header with appropriate ARIA attributes for accessibility.
|
|
15
14
|
*
|
|
16
15
|
* ### Usage Guidelines
|
|
@@ -27,7 +26,7 @@ import '../../icons/icon-chevron-down-google.js';
|
|
|
27
26
|
* ### Slots
|
|
28
27
|
* | Slot Name | Renders When... | Purpose |
|
|
29
28
|
* |-------------------|--------------------------|-------------------------------------------------|
|
|
30
|
-
* | expanded-content |
|
|
29
|
+
* | expanded-content | Always | Custom content revealed while the item is open |
|
|
31
30
|
*
|
|
32
31
|
* ### Events
|
|
33
32
|
* - `accordion-item-toggle` – Fired when the item is toggled open or closed. Event detail: `{ open: boolean, title: string }`
|
|
@@ -52,8 +51,9 @@ import '../../icons/icon-chevron-down-google.js';
|
|
|
52
51
|
* @property disabled - Disables the accordion item, preventing user interaction and dimming the appearance.
|
|
53
52
|
* @property showDivider - Displays a divider line below the item for visual separation.
|
|
54
53
|
* Useful when stacking multiple items in a list.
|
|
55
|
-
* @slot expanded-content - Content
|
|
54
|
+
* @slot expanded-content - Content revealed while the item is open.
|
|
56
55
|
* @fires {CustomEvent<{open: boolean, title: string}>} accordion-item-toggle - Fired when the item is toggled open or closed.
|
|
56
|
+
* @cssprop [--obc-accordion-expand-duration=200ms] - How long the panel takes to open and close. The chevron and the header's corners follow it. Ignored under `prefers-reduced-motion: reduce`.
|
|
57
57
|
* @stable
|
|
58
58
|
*/
|
|
59
59
|
export declare class ObcAccordionItem extends LitElement {
|
|
@@ -66,6 +66,15 @@ export declare class ObcAccordionItem extends LitElement {
|
|
|
66
66
|
/** Displays a divider line below the item for visual separation. Useful when stacking multiple items in a list. */
|
|
67
67
|
showDivider: boolean;
|
|
68
68
|
private handleToggle;
|
|
69
|
+
/**
|
|
70
|
+
* Keeps the keyboard somewhere predictable when the panel closes.
|
|
71
|
+
*
|
|
72
|
+
* A collapsed panel is `inert`, and the browser drops focus out of anything
|
|
73
|
+
* it makes inert — onto `<body>`, two frames later. Clicking the header
|
|
74
|
+
* already leaves focus there; a consumer setting `open` while a slotted
|
|
75
|
+
* control has focus is the case that needs the transfer.
|
|
76
|
+
*/
|
|
77
|
+
willUpdate(changed: PropertyValues<this>): void;
|
|
69
78
|
private renderContent;
|
|
70
79
|
private renderExpandedContent;
|
|
71
80
|
private renderDivider;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"accordion-item.d.ts","sourceRoot":"","sources":["../../../src/components/accordion-item/accordion-item.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,UAAU,
|
|
1
|
+
{"version":3,"file":"accordion-item.d.ts","sourceRoot":"","sources":["../../../src/components/accordion-item/accordion-item.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,UAAU,EAAmB,KAAK,cAAc,EAAC,MAAM,KAAK,CAAC;AAMrE,OAAO,yCAAyC,CAAC;AAEjD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAuDG;AACH,qBACa,gBAAiB,SAAQ,UAAU;IACX,KAAK,SAAM;IAEnB,IAAI,UAAS;IAEb,QAAQ,UAAS;IAEjB,WAAW,UAAS;IAE/C,OAAO,CAAC,YAAY;IAepB;;;;;;;OAOG;IACM,UAAU,CAAC,OAAO,EAAE,cAAc,CAAC,IAAI,CAAC;IAYjD,OAAO,CAAC,aAAa;IAerB,OAAO,CAAC,qBAAqB;IAY7B,OAAO,CAAC,aAAa;IAMZ,MAAM;IA0Bf,OAAgB,MAAM,0BAA6B;CACpD;AAED,OAAO,CAAC,MAAM,CAAC;IACb,UAAU,qBAAqB;QAC7B,oBAAoB,EAAE,gBAAgB,CAAC;KACxC;CACF"}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { customElement } from "../../decorator.js";
|
|
2
2
|
import __decorate from "../../_virtual/_@oxc-project_runtime@0.150.0/helpers/esm/decorate.js";
|
|
3
3
|
import "../../icons/icon-chevron-down-google.js";
|
|
4
|
+
import { releaseFocusBefore } from "../../internal/focus.js";
|
|
4
5
|
import accordion_item_default from "./accordion-item.css.js";
|
|
5
6
|
import { LitElement, html, unsafeCSS } from "lit";
|
|
6
7
|
import { property } from "lit/decorators.js";
|
|
@@ -22,6 +23,20 @@ var ObcAccordionItem = class ObcAccordionItem extends LitElement {
|
|
|
22
23
|
title: this.title
|
|
23
24
|
} }));
|
|
24
25
|
}
|
|
26
|
+
/**
|
|
27
|
+
* Keeps the keyboard somewhere predictable when the panel closes.
|
|
28
|
+
*
|
|
29
|
+
* A collapsed panel is `inert`, and the browser drops focus out of anything
|
|
30
|
+
* it makes inert — onto `<body>`, two frames later. Clicking the header
|
|
31
|
+
* already leaves focus there; a consumer setting `open` while a slotted
|
|
32
|
+
* control has focus is the case that needs the transfer.
|
|
33
|
+
*/
|
|
34
|
+
willUpdate(changed) {
|
|
35
|
+
if (!changed.has("open") || this.open) return;
|
|
36
|
+
const panel = this.shadowRoot?.querySelector(".panel");
|
|
37
|
+
if (!panel) return;
|
|
38
|
+
releaseFocusBefore(panel, this.shadowRoot?.querySelector(".content-button"), this.shadowRoot?.querySelector(".wrapper"));
|
|
39
|
+
}
|
|
25
40
|
renderContent() {
|
|
26
41
|
return html`
|
|
27
42
|
<div class="content">
|
|
@@ -37,10 +52,13 @@ var ObcAccordionItem = class ObcAccordionItem extends LitElement {
|
|
|
37
52
|
`;
|
|
38
53
|
}
|
|
39
54
|
renderExpandedContent() {
|
|
40
|
-
if (!this.open) return "";
|
|
41
55
|
return html`
|
|
42
|
-
<div class="content
|
|
43
|
-
<
|
|
56
|
+
<div class="panel" id="accordion-content" ?inert=${!this.open}>
|
|
57
|
+
<div class="panel-inner">
|
|
58
|
+
<div class="content-container">
|
|
59
|
+
<slot name="expanded-content"></slot>
|
|
60
|
+
</div>
|
|
61
|
+
</div>
|
|
44
62
|
</div>
|
|
45
63
|
`;
|
|
46
64
|
}
|
|
@@ -51,6 +69,7 @@ var ObcAccordionItem = class ObcAccordionItem extends LitElement {
|
|
|
51
69
|
render() {
|
|
52
70
|
return html`
|
|
53
71
|
<div
|
|
72
|
+
tabindex="-1"
|
|
54
73
|
class=${classMap({
|
|
55
74
|
wrapper: true,
|
|
56
75
|
"state-disabled": this.disabled,
|
|
@@ -63,6 +82,7 @@ var ObcAccordionItem = class ObcAccordionItem extends LitElement {
|
|
|
63
82
|
@click=${this.handleToggle}
|
|
64
83
|
?disabled=${this.disabled}
|
|
65
84
|
aria-expanded=${this.open}
|
|
85
|
+
aria-controls="accordion-content"
|
|
66
86
|
>
|
|
67
87
|
${this.renderContent()}
|
|
68
88
|
</button>
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"accordion-item.js","names":[],"sources":["../../../src/components/accordion-item/accordion-item.ts"],"sourcesContent":["import {LitElement, html, unsafeCSS} from 'lit';\nimport {customElement} from '../../decorator.js';\nimport {classMap} from 'lit/directives/class-map.js';\nimport componentStyle from './accordion-item.css?inline';\nimport {property} from 'lit/decorators.js';\nimport '../../icons/icon-chevron-down-google.js';\n\n/**\n * `<obc-accordion-item>` – A collapsible section component for toggling the visibility of content panels (commonly known as an accordion item, expandable panel, or disclosure).\n *\n * Provides a single expandable/collapsible section with a clickable header and an optional content area. Useful for organizing related information in a compact, vertically stacked layout, allowing users to reveal or hide details as needed.\n *\n * ### Features\n * - **Toggleable Expansion:** Click the header to expand or collapse the content area. The
|
|
1
|
+
{"version":3,"file":"accordion-item.js","names":[],"sources":["../../../src/components/accordion-item/accordion-item.ts"],"sourcesContent":["import {LitElement, html, unsafeCSS, type PropertyValues} from 'lit';\nimport {customElement} from '../../decorator.js';\nimport {releaseFocusBefore} from '../../internal/focus.js';\nimport {classMap} from 'lit/directives/class-map.js';\nimport componentStyle from './accordion-item.css?inline';\nimport {property} from 'lit/decorators.js';\nimport '../../icons/icon-chevron-down-google.js';\n\n/**\n * `<obc-accordion-item>` – A collapsible section component for toggling the visibility of content panels (commonly known as an accordion item, expandable panel, or disclosure).\n *\n * Provides a single expandable/collapsible section with a clickable header and an optional content area. Useful for organizing related information in a compact, vertically stacked layout, allowing users to reveal or hide details as needed.\n *\n * ### Features\n * - **Toggleable Expansion:** Click the header to expand or collapse the content area. The panel slides open and closed, and the chevron turns with it; `prefers-reduced-motion: reduce` switches instantly instead.\n * - **Disabled State:** Prevents user interaction and visually indicates non-interactivity.\n * - **Customizable Content:** Slot for custom expanded content (`expanded-content`), supporting any HTML or component.\n * - **Optional Divider:** Can display a divider line below the item for visual separation in lists.\n * - **Accessible:** Uses a button for the header with appropriate ARIA attributes for accessibility.\n *\n * ### Usage Guidelines\n * Use `obc-accordion-item` to organize content into expandable sections, such as FAQs, settings panels, or grouped lists. Ideal when you want to let users scan section titles and expand only those relevant to them. For multi-item accordions, stack several `obc-accordion-item` components vertically.\n *\n * - Use the `title` property for the section label.\n * - Place any custom content (text, forms, components) in the `expanded-content` slot.\n * - Use the `disabled` property to prevent interaction for items that should not be toggled.\n * - Use the `showDivider` property to visually separate items in a list.\n * - If you need a persistent panel (not collapsible), use a different container component.\n *\n * **TODO(designer):** Confirm if there are recommended patterns for managing open/close state in multi-item accordions (e.g., only one open at a time), or if this is left to the developer.\n *\n * ### Slots\n * | Slot Name | Renders When... | Purpose |\n * |-------------------|--------------------------|-------------------------------------------------|\n * | expanded-content | Always | Custom content revealed while the item is open |\n *\n * ### Events\n * - `accordion-item-toggle` – Fired when the item is toggled open or closed. Event detail: `{ open: boolean, title: string }`\n *\n * ### Best Practices\n * - Keep section titles concise for easy scanning.\n * - Avoid placing interactive controls in the header area to prevent accidental toggling.\n * - For accessibility, ensure each item’s title is unique within a group.\n *\n * **Example:**\n * ```\n * <obc-accordion-item title=\"Details\" .open=${false}>\n * <div slot=\"expanded-content\">\n * <p>Additional information goes here.</p>\n * </div>\n * </obc-accordion-item>\n * ```\n *\n * @property title - The label displayed in the header of the accordion item.\n * @property open - Whether the item is expanded (shows the content area).\n * Set to `true` to expand, `false` to collapse.\n * @property disabled - Disables the accordion item, preventing user interaction and dimming the appearance.\n * @property showDivider - Displays a divider line below the item for visual separation.\n * Useful when stacking multiple items in a list.\n * @slot expanded-content - Content revealed while the item is open.\n * @fires {CustomEvent<{open: boolean, title: string}>} accordion-item-toggle - Fired when the item is toggled open or closed.\n * @cssprop [--obc-accordion-expand-duration=200ms] - How long the panel takes to open and close. The chevron and the header's corners follow it. Ignored under `prefers-reduced-motion: reduce`.\n * @stable\n */\n@customElement('obc-accordion-item')\nexport class ObcAccordionItem extends LitElement {\n @property({type: String}) override title = '';\n\n @property({type: Boolean}) open = false;\n\n @property({type: Boolean}) disabled = false;\n\n @property({type: Boolean}) showDivider = false;\n\n private handleToggle() {\n if (this.disabled) return;\n\n this.open = !this.open;\n\n this.dispatchEvent(\n new CustomEvent('accordion-item-toggle', {\n detail: {\n open: this.open,\n title: this.title,\n },\n })\n );\n }\n\n /**\n * Keeps the keyboard somewhere predictable when the panel closes.\n *\n * A collapsed panel is `inert`, and the browser drops focus out of anything\n * it makes inert — onto `<body>`, two frames later. Clicking the header\n * already leaves focus there; a consumer setting `open` while a slotted\n * control has focus is the case that needs the transfer.\n */\n override willUpdate(changed: PropertyValues<this>) {\n if (!changed.has('open') || this.open) return;\n\n const panel = this.shadowRoot?.querySelector('.panel');\n if (!panel) return;\n releaseFocusBefore(\n panel,\n this.shadowRoot?.querySelector<HTMLButtonElement>('.content-button'),\n this.shadowRoot?.querySelector<HTMLElement>('.wrapper')\n );\n }\n\n private renderContent() {\n return html`\n <div class=\"content\">\n <div class=\"leading-content-container\">\n <div class=\"label-frame\">\n <div class=\"title\">${this.title}</div>\n </div>\n </div>\n <div class=\"trailing-icon\">\n <obi-chevron-down-google></obi-chevron-down-google>\n </div>\n </div>\n `;\n }\n\n private renderExpandedContent() {\n return html`\n <div class=\"panel\" id=\"accordion-content\" ?inert=${!this.open}>\n <div class=\"panel-inner\">\n <div class=\"content-container\">\n <slot name=\"expanded-content\"></slot>\n </div>\n </div>\n </div>\n `;\n }\n\n private renderDivider() {\n if (!this.showDivider) return '';\n\n return html`<div class=\"divider\"></div>`;\n }\n\n override render() {\n return html`\n <div\n tabindex=\"-1\"\n class=${classMap({\n wrapper: true,\n 'state-disabled': this.disabled,\n 'open-true': this.open,\n 'open-false': !this.open,\n })}\n >\n <button\n class=\"content-button\"\n @click=${this.handleToggle}\n ?disabled=${this.disabled}\n aria-expanded=${this.open}\n aria-controls=\"accordion-content\"\n >\n ${this.renderContent()}\n </button>\n\n ${this.renderExpandedContent()} ${this.renderDivider()}\n </div>\n `;\n }\n\n static override styles = unsafeCSS(componentStyle);\n}\n\ndeclare global {\n interface HTMLElementTagNameMap {\n 'obc-accordion-item': ObcAccordionItem;\n }\n}\n"],"mappings":";;;;;;;;;AAiEO,IAAM,mBAAN,MAAM,yBAAyB,WAAW;;;EACJ,KAAA,QAAA;EAET,KAAA,OAAA;EAEI,KAAA,WAAA;EAEG,KAAA,cAAA;;CAEzC,eAAuB;EACrB,IAAI,KAAK,UAAU;EAEnB,KAAK,OAAO,CAAC,KAAK;EAElB,KAAK,cACH,IAAI,YAAY,yBAAyB,EACvC,QAAQ;GACN,MAAM,KAAK;GACX,OAAO,KAAK;EACd,EACF,CAAC,CACH;CACF;;;;;;;;;CAUA,WAAoB,SAA+B;EACjD,IAAI,CAAC,QAAQ,IAAI,MAAM,KAAK,KAAK,MAAM;EAEvC,MAAM,QAAQ,KAAK,YAAY,cAAc,QAAQ;EACrD,IAAI,CAAC,OAAO;EACZ,mBACE,OACA,KAAK,YAAY,cAAiC,iBAAiB,GACnE,KAAK,YAAY,cAA2B,UAAU,CACxD;CACF;CAEA,gBAAwB;EACtB,OAAO,IAAI;;;;iCAIkB,KAAK,MAAM;;;;;;;;CAQ1C;CAEA,wBAAgC;EAC9B,OAAO,IAAI;yDAC0C,CAAC,KAAK,KAAK;;;;;;;;CAQlE;CAEA,gBAAwB;EACtB,IAAI,CAAC,KAAK,aAAa,OAAO;EAE9B,OAAO,IAAI;CACb;CAEA,SAAkB;EAChB,OAAO,IAAI;;;gBAGC,SAAS;GACf,SAAS;GACT,kBAAkB,KAAK;GACvB,aAAa,KAAK;GAClB,cAAc,CAAC,KAAK;EACtB,CAAC,EAAE;;;;mBAIQ,KAAK,aAAa;sBACf,KAAK,SAAS;0BACV,KAAK,KAAK;;;YAGxB,KAAK,cAAc,EAAE;;;UAGvB,KAAK,sBAAsB,EAAE,GAAG,KAAK,cAAc,EAAE;;;CAG7D;;EAEyB,KAAA,SAAA,UAAU,sBAAc;;AACnD;AAvGG,WAAA,CAAA,SAAS,EAAC,MAAM,OAAM,CAAC,CAAA,GAAA,iBAAA,WAAA,SAAA,KAAA,CAAA;AAEvB,WAAA,CAAA,SAAS,EAAC,MAAM,QAAO,CAAC,CAAA,GAAA,iBAAA,WAAA,QAAA,KAAA,CAAA;AAExB,WAAA,CAAA,SAAS,EAAC,MAAM,QAAO,CAAC,CAAA,GAAA,iBAAA,WAAA,YAAA,KAAA,CAAA;AAExB,WAAA,CAAA,SAAS,EAAC,MAAM,QAAO,CAAC,CAAA,GAAA,iBAAA,WAAA,eAAA,KAAA,CAAA;AAR1B,mBAAA,WAAA,CAAA,cAAc,oBAAoB,CAAA,GAAA,gBAAA"}
|
package/dist/internal/focus.d.ts
CHANGED
|
@@ -8,6 +8,29 @@
|
|
|
8
8
|
*/
|
|
9
9
|
/** The focused element, following every open shadow root down. */
|
|
10
10
|
export declare function deepActiveElement(): Element | null;
|
|
11
|
+
/**
|
|
12
|
+
* Whether `node` sits inside `root` in the composed tree.
|
|
13
|
+
*
|
|
14
|
+
* `Node.contains()` walks the DOM tree, where slotted light-DOM content is a
|
|
15
|
+
* child of the host and not of the slot — so it answers no for exactly the
|
|
16
|
+
* content a component projects into itself. This follows `assignedSlot` and
|
|
17
|
+
* shadow hosts as well.
|
|
18
|
+
*/
|
|
19
|
+
export declare function composedContains(root: Node, node: Node | null): boolean;
|
|
20
|
+
/**
|
|
21
|
+
* Moves focus out of `hidden`, to the first fallback that will take it.
|
|
22
|
+
*
|
|
23
|
+
* Call it just before a region becomes `inert` or is taken out of the page.
|
|
24
|
+
* The browser blurs whatever it hides, and focus lands on `<body>` a frame or
|
|
25
|
+
* two later, so the next Tab press starts from the top of the document instead
|
|
26
|
+
* of where the user was.
|
|
27
|
+
*
|
|
28
|
+
* Each candidate is tried and then checked, rather than inspected first: a
|
|
29
|
+
* `disabled` button, a hidden one and an element with no tabindex all refuse
|
|
30
|
+
* focus for different reasons, and the only reliable question is whether focus
|
|
31
|
+
* actually left.
|
|
32
|
+
*/
|
|
33
|
+
export declare function releaseFocusBefore(hidden: Node, ...fallbacks: (HTMLElement | null | undefined)[]): void;
|
|
11
34
|
/**
|
|
12
35
|
* The elements under `root` a Tab press could land on, in rendered order:
|
|
13
36
|
* shadow children before light children, light children only where a slot
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"focus.d.ts","sourceRoot":"","sources":["../../src/internal/focus.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAKH,kEAAkE;AAClE,wBAAgB,iBAAiB,IAAI,OAAO,GAAG,IAAI,CAMlD;AASD;;;;GAIG;AACH,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,IAAI,GAAG,WAAW,EAAE,CAkB3D"}
|
|
1
|
+
{"version":3,"file":"focus.d.ts","sourceRoot":"","sources":["../../src/internal/focus.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAKH,kEAAkE;AAClE,wBAAgB,iBAAiB,IAAI,OAAO,GAAG,IAAI,CAMlD;AAED;;;;;;;GAOG;AACH,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,GAAG,IAAI,GAAG,OAAO,CAUvE;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,kBAAkB,CAChC,MAAM,EAAE,IAAI,EACZ,GAAG,SAAS,EAAE,CAAC,WAAW,GAAG,IAAI,GAAG,SAAS,CAAC,EAAE,GAC/C,IAAI,CAON;AASD;;;;GAIG;AACH,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,IAAI,GAAG,WAAW,EAAE,CAkB3D"}
|
package/dist/internal/focus.js
CHANGED
|
@@ -14,6 +14,43 @@ function deepActiveElement() {
|
|
|
14
14
|
while (active?.shadowRoot?.activeElement) active = active.shadowRoot.activeElement;
|
|
15
15
|
return active;
|
|
16
16
|
}
|
|
17
|
+
/**
|
|
18
|
+
* Whether `node` sits inside `root` in the composed tree.
|
|
19
|
+
*
|
|
20
|
+
* `Node.contains()` walks the DOM tree, where slotted light-DOM content is a
|
|
21
|
+
* child of the host and not of the slot — so it answers no for exactly the
|
|
22
|
+
* content a component projects into itself. This follows `assignedSlot` and
|
|
23
|
+
* shadow hosts as well.
|
|
24
|
+
*/
|
|
25
|
+
function composedContains(root, node) {
|
|
26
|
+
let current = node;
|
|
27
|
+
while (current) {
|
|
28
|
+
if (current === root) return true;
|
|
29
|
+
current = current.assignedSlot ?? current.parentNode ?? (current instanceof ShadowRoot ? current.host : null);
|
|
30
|
+
}
|
|
31
|
+
return false;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Moves focus out of `hidden`, to the first fallback that will take it.
|
|
35
|
+
*
|
|
36
|
+
* Call it just before a region becomes `inert` or is taken out of the page.
|
|
37
|
+
* The browser blurs whatever it hides, and focus lands on `<body>` a frame or
|
|
38
|
+
* two later, so the next Tab press starts from the top of the document instead
|
|
39
|
+
* of where the user was.
|
|
40
|
+
*
|
|
41
|
+
* Each candidate is tried and then checked, rather than inspected first: a
|
|
42
|
+
* `disabled` button, a hidden one and an element with no tabindex all refuse
|
|
43
|
+
* focus for different reasons, and the only reliable question is whether focus
|
|
44
|
+
* actually left.
|
|
45
|
+
*/
|
|
46
|
+
function releaseFocusBefore(hidden, ...fallbacks) {
|
|
47
|
+
if (!composedContains(hidden, deepActiveElement())) return;
|
|
48
|
+
for (const candidate of fallbacks) {
|
|
49
|
+
if (!candidate) continue;
|
|
50
|
+
candidate.focus();
|
|
51
|
+
if (!composedContains(hidden, deepActiveElement())) return;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
17
54
|
function isTabbable(element) {
|
|
18
55
|
if (!element.matches(TABBABLE_SELECTOR)) return false;
|
|
19
56
|
if (element.tabIndex < 0) return false;
|
|
@@ -45,6 +82,6 @@ function composedTabbables(root) {
|
|
|
45
82
|
return found;
|
|
46
83
|
}
|
|
47
84
|
//#endregion
|
|
48
|
-
export { composedTabbables, deepActiveElement };
|
|
85
|
+
export { composedContains, composedTabbables, deepActiveElement, releaseFocusBefore };
|
|
49
86
|
|
|
50
87
|
//# sourceMappingURL=focus.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"focus.js","names":[],"sources":["../../src/internal/focus.ts"],"sourcesContent":["/**\n * Focus queries that see through open shadow roots.\n *\n * `document.activeElement` and `querySelectorAll` both stop at a shadow\n * boundary, so a component that focuses a control it renders reads as\n * unfocused from outside, and a dialog cannot find the controls it has to\n * cycle between. These walk the composed tree instead.\n */\n\nconst TABBABLE_SELECTOR =\n 'a[href], button, input, select, textarea, [tabindex], [contenteditable=\"true\"]';\n\n/** The focused element, following every open shadow root down. */\nexport function deepActiveElement(): Element | null {\n let active = document.activeElement;\n while (active?.shadowRoot?.activeElement) {\n active = active.shadowRoot.activeElement;\n }\n return active;\n}\n\nfunction isTabbable(element: Element): element is HTMLElement {\n if (!element.matches(TABBABLE_SELECTOR)) return false;\n if ((element as HTMLElement).tabIndex < 0) return false;\n if ((element as HTMLButtonElement).disabled) return false;\n return element.getClientRects().length > 0;\n}\n\n/**\n * The elements under `root` a Tab press could land on, in rendered order:\n * shadow children before light children, light children only where a slot\n * places them.\n */\nexport function composedTabbables(root: Node): HTMLElement[] {\n const found: HTMLElement[] = [];\n const visit = (node: Node) => {\n if (node instanceof HTMLSlotElement) {\n node.assignedNodes({flatten: true}).forEach(visit);\n return;\n }\n if (node instanceof Element) {\n if (isTabbable(node)) found.push(node);\n if (node.shadowRoot) {\n Array.from(node.shadowRoot.childNodes).forEach(visit);\n return;\n }\n }\n Array.from(node.childNodes).forEach(visit);\n };\n visit(root);\n return found;\n}\n"],"mappings":";;;;;;;;;AASA,IAAM,oBACJ;;AAGF,SAAgB,oBAAoC;CAClD,IAAI,SAAS,SAAS;CACtB,OAAO,QAAQ,YAAY,eACzB,SAAS,OAAO,WAAW;CAE7B,OAAO;AACT;AAEA,SAAS,WAAW,SAA0C;CAC5D,IAAI,CAAC,QAAQ,QAAQ,iBAAiB,GAAG,OAAO;CAChD,IAAK,QAAwB,WAAW,GAAG,OAAO;CAClD,IAAK,QAA8B,UAAU,OAAO;CACpD,OAAO,QAAQ,eAAe,CAAC,CAAC,SAAS;AAC3C;;;;;;AAOA,SAAgB,kBAAkB,MAA2B;CAC3D,MAAM,QAAuB,CAAC;CAC9B,MAAM,SAAS,SAAe;EAC5B,IAAI,gBAAgB,iBAAiB;GACnC,KAAK,cAAc,EAAC,SAAS,KAAI,CAAC,CAAC,CAAC,QAAQ,KAAK;GACjD;EACF;EACA,IAAI,gBAAgB,SAAS;GAC3B,IAAI,WAAW,IAAI,GAAG,MAAM,KAAK,IAAI;GACrC,IAAI,KAAK,YAAY;IACnB,MAAM,KAAK,KAAK,WAAW,UAAU,CAAC,CAAC,QAAQ,KAAK;IACpD;GACF;EACF;EACA,MAAM,KAAK,KAAK,UAAU,CAAC,CAAC,QAAQ,KAAK;CAC3C;CACA,MAAM,IAAI;CACV,OAAO;AACT"}
|
|
1
|
+
{"version":3,"file":"focus.js","names":[],"sources":["../../src/internal/focus.ts"],"sourcesContent":["/**\n * Focus queries that see through open shadow roots.\n *\n * `document.activeElement` and `querySelectorAll` both stop at a shadow\n * boundary, so a component that focuses a control it renders reads as\n * unfocused from outside, and a dialog cannot find the controls it has to\n * cycle between. These walk the composed tree instead.\n */\n\nconst TABBABLE_SELECTOR =\n 'a[href], button, input, select, textarea, [tabindex], [contenteditable=\"true\"]';\n\n/** The focused element, following every open shadow root down. */\nexport function deepActiveElement(): Element | null {\n let active = document.activeElement;\n while (active?.shadowRoot?.activeElement) {\n active = active.shadowRoot.activeElement;\n }\n return active;\n}\n\n/**\n * Whether `node` sits inside `root` in the composed tree.\n *\n * `Node.contains()` walks the DOM tree, where slotted light-DOM content is a\n * child of the host and not of the slot — so it answers no for exactly the\n * content a component projects into itself. This follows `assignedSlot` and\n * shadow hosts as well.\n */\nexport function composedContains(root: Node, node: Node | null): boolean {\n let current: Node | null = node;\n while (current) {\n if (current === root) return true;\n current =\n (current as Element).assignedSlot ??\n current.parentNode ??\n (current instanceof ShadowRoot ? current.host : null);\n }\n return false;\n}\n\n/**\n * Moves focus out of `hidden`, to the first fallback that will take it.\n *\n * Call it just before a region becomes `inert` or is taken out of the page.\n * The browser blurs whatever it hides, and focus lands on `<body>` a frame or\n * two later, so the next Tab press starts from the top of the document instead\n * of where the user was.\n *\n * Each candidate is tried and then checked, rather than inspected first: a\n * `disabled` button, a hidden one and an element with no tabindex all refuse\n * focus for different reasons, and the only reliable question is whether focus\n * actually left.\n */\nexport function releaseFocusBefore(\n hidden: Node,\n ...fallbacks: (HTMLElement | null | undefined)[]\n): void {\n if (!composedContains(hidden, deepActiveElement())) return;\n for (const candidate of fallbacks) {\n if (!candidate) continue;\n candidate.focus();\n if (!composedContains(hidden, deepActiveElement())) return;\n }\n}\n\nfunction isTabbable(element: Element): element is HTMLElement {\n if (!element.matches(TABBABLE_SELECTOR)) return false;\n if ((element as HTMLElement).tabIndex < 0) return false;\n if ((element as HTMLButtonElement).disabled) return false;\n return element.getClientRects().length > 0;\n}\n\n/**\n * The elements under `root` a Tab press could land on, in rendered order:\n * shadow children before light children, light children only where a slot\n * places them.\n */\nexport function composedTabbables(root: Node): HTMLElement[] {\n const found: HTMLElement[] = [];\n const visit = (node: Node) => {\n if (node instanceof HTMLSlotElement) {\n node.assignedNodes({flatten: true}).forEach(visit);\n return;\n }\n if (node instanceof Element) {\n if (isTabbable(node)) found.push(node);\n if (node.shadowRoot) {\n Array.from(node.shadowRoot.childNodes).forEach(visit);\n return;\n }\n }\n Array.from(node.childNodes).forEach(visit);\n };\n visit(root);\n return found;\n}\n"],"mappings":";;;;;;;;;AASA,IAAM,oBACJ;;AAGF,SAAgB,oBAAoC;CAClD,IAAI,SAAS,SAAS;CACtB,OAAO,QAAQ,YAAY,eACzB,SAAS,OAAO,WAAW;CAE7B,OAAO;AACT;;;;;;;;;AAUA,SAAgB,iBAAiB,MAAY,MAA4B;CACvE,IAAI,UAAuB;CAC3B,OAAO,SAAS;EACd,IAAI,YAAY,MAAM,OAAO;EAC7B,UACG,QAAoB,gBACrB,QAAQ,eACP,mBAAmB,aAAa,QAAQ,OAAO;CACpD;CACA,OAAO;AACT;;;;;;;;;;;;;;AAeA,SAAgB,mBACd,QACA,GAAG,WACG;CACN,IAAI,CAAC,iBAAiB,QAAQ,kBAAkB,CAAC,GAAG;CACpD,KAAK,MAAM,aAAa,WAAW;EACjC,IAAI,CAAC,WAAW;EAChB,UAAU,MAAM;EAChB,IAAI,CAAC,iBAAiB,QAAQ,kBAAkB,CAAC,GAAG;CACtD;AACF;AAEA,SAAS,WAAW,SAA0C;CAC5D,IAAI,CAAC,QAAQ,QAAQ,iBAAiB,GAAG,OAAO;CAChD,IAAK,QAAwB,WAAW,GAAG,OAAO;CAClD,IAAK,QAA8B,UAAU,OAAO;CACpD,OAAO,QAAQ,eAAe,CAAC,CAAC,SAAS;AAC3C;;;;;;AAOA,SAAgB,kBAAkB,MAA2B;CAC3D,MAAM,QAAuB,CAAC;CAC9B,MAAM,SAAS,SAAe;EAC5B,IAAI,gBAAgB,iBAAiB;GACnC,KAAK,cAAc,EAAC,SAAS,KAAI,CAAC,CAAC,CAAC,QAAQ,KAAK;GACjD;EACF;EACA,IAAI,gBAAgB,SAAS;GAC3B,IAAI,WAAW,IAAI,GAAG,MAAM,KAAK,IAAI;GACrC,IAAI,KAAK,YAAY;IACnB,MAAM,KAAK,KAAK,WAAW,UAAU,CAAC,CAAC,QAAQ,KAAK;IACpD;GACF;EACF;EACA,MAAM,KAAK,KAAK,UAAU,CAAC,CAAC,QAAQ,KAAK;CAC3C;CACA,MAAM,IAAI;CACV,OAAO;AACT"}
|
package/eslint.config.mjs
CHANGED
|
@@ -1077,6 +1077,60 @@ export const openbridgePlugin = {
|
|
|
1077
1077
|
};
|
|
1078
1078
|
},
|
|
1079
1079
|
},
|
|
1080
|
+
|
|
1081
|
+
// Svelte binds an `on…={…}` markup attribute as an event listener, so a
|
|
1082
|
+
// property named like one cannot be set from a template (#1090).
|
|
1083
|
+
'no-event-like-property-name': {
|
|
1084
|
+
meta: {
|
|
1085
|
+
type: 'problem',
|
|
1086
|
+
docs: {
|
|
1087
|
+
description:
|
|
1088
|
+
'Keep @property names and attributes from starting with `on`',
|
|
1089
|
+
},
|
|
1090
|
+
schema: [],
|
|
1091
|
+
},
|
|
1092
|
+
create(context) {
|
|
1093
|
+
const propertyOptions = (node) => {
|
|
1094
|
+
for (const decorator of node.decorators ?? []) {
|
|
1095
|
+
const expr = decorator.expression;
|
|
1096
|
+
if (
|
|
1097
|
+
expr?.type === 'CallExpression' &&
|
|
1098
|
+
expr.callee.type === 'Identifier' &&
|
|
1099
|
+
expr.callee.name === 'property'
|
|
1100
|
+
) {
|
|
1101
|
+
return expr.arguments[0]?.properties ?? [];
|
|
1102
|
+
}
|
|
1103
|
+
}
|
|
1104
|
+
return null;
|
|
1105
|
+
};
|
|
1106
|
+
const check = (node) => {
|
|
1107
|
+
if (node.key.type !== 'Identifier') return;
|
|
1108
|
+
const options = propertyOptions(node);
|
|
1109
|
+
if (!options) return;
|
|
1110
|
+
const attribute = options.find(
|
|
1111
|
+
(p) =>
|
|
1112
|
+
p.type === 'Property' &&
|
|
1113
|
+
p.key.type === 'Identifier' &&
|
|
1114
|
+
p.key.name === 'attribute' &&
|
|
1115
|
+
p.value.type === 'Literal' &&
|
|
1116
|
+
typeof p.value.value === 'string'
|
|
1117
|
+
)?.value.value;
|
|
1118
|
+
const name = [node.key.name, attribute].find(
|
|
1119
|
+
(n) => typeof n === 'string' && /^on/i.test(n)
|
|
1120
|
+
);
|
|
1121
|
+
if (!name) return;
|
|
1122
|
+
context.report({
|
|
1123
|
+
node: node.key,
|
|
1124
|
+
message: `\`${name}\` starts with \`on\`, which Svelte binds as an event listener in markup, so the property cannot be set there (docs/agents/coding-standards.md § Property names).`,
|
|
1125
|
+
});
|
|
1126
|
+
};
|
|
1127
|
+
return {
|
|
1128
|
+
PropertyDefinition: check,
|
|
1129
|
+
MethodDefinition: check,
|
|
1130
|
+
AccessorProperty: check,
|
|
1131
|
+
};
|
|
1132
|
+
},
|
|
1133
|
+
},
|
|
1080
1134
|
},
|
|
1081
1135
|
};
|
|
1082
1136
|
|
|
@@ -1128,6 +1182,7 @@ export default [
|
|
|
1128
1182
|
'openbridge/use-math-helpers': 'error',
|
|
1129
1183
|
'openbridge/no-positive-tabindex': 'error',
|
|
1130
1184
|
'openbridge/positive-boolean-name': 'error',
|
|
1185
|
+
'openbridge/no-event-like-property-name': 'error',
|
|
1131
1186
|
'openbridge/storybook-title-case': 'off',
|
|
1132
1187
|
'openbridge/story-lifecycle-tags': 'off',
|
|
1133
1188
|
// Disabled because eslint-plugin-file-extension-in-import-ts is not yet
|
|
@@ -1163,6 +1218,7 @@ export default [
|
|
|
1163
1218
|
'openbridge/use-math-helpers': 'off',
|
|
1164
1219
|
'openbridge/no-positive-tabindex': 'off',
|
|
1165
1220
|
'openbridge/positive-boolean-name': 'off',
|
|
1221
|
+
'openbridge/no-event-like-property-name': 'off',
|
|
1166
1222
|
},
|
|
1167
1223
|
},
|
|
1168
1224
|
{
|
package/package.json
CHANGED
|
@@ -440,3 +440,47 @@ describe('openbridge/positive-boolean-name', () => {
|
|
|
440
440
|
);
|
|
441
441
|
});
|
|
442
442
|
});
|
|
443
|
+
|
|
444
|
+
describe('openbridge/no-event-like-property-name', () => {
|
|
445
|
+
it('rejects properties and attributes that start with on', () => {
|
|
446
|
+
ruleTester.run(
|
|
447
|
+
'no-event-like-property-name',
|
|
448
|
+
openbridgePlugin.rules['no-event-like-property-name'],
|
|
449
|
+
{
|
|
450
|
+
valid: [
|
|
451
|
+
'class A { @property({type: Boolean}) turnedOn = false; }',
|
|
452
|
+
"class A { @property({type: Boolean, attribute: 'is-on'}) active = false; }",
|
|
453
|
+
'class A { @state() onHold = false; }',
|
|
454
|
+
'class A { get _on() { return true; } }',
|
|
455
|
+
'class A { onClick = () => {}; }',
|
|
456
|
+
],
|
|
457
|
+
invalid: [
|
|
458
|
+
{
|
|
459
|
+
code: 'class A { @property({type: Boolean}) on = false; }',
|
|
460
|
+
errors: 1,
|
|
461
|
+
},
|
|
462
|
+
{
|
|
463
|
+
code: 'class A { @property({type: String}) onTop = ""; }',
|
|
464
|
+
errors: 1,
|
|
465
|
+
},
|
|
466
|
+
{
|
|
467
|
+
code: "class A { @property({type: Boolean, attribute: 'on-state'}) active = false; }",
|
|
468
|
+
errors: 1,
|
|
469
|
+
},
|
|
470
|
+
{
|
|
471
|
+
code: "class A { @property({type: Boolean, attribute: 'hold'}) onHold = false; }",
|
|
472
|
+
errors: 1,
|
|
473
|
+
},
|
|
474
|
+
{
|
|
475
|
+
code: 'class A { @property({type: Boolean}) set on(v) {} }',
|
|
476
|
+
errors: 1,
|
|
477
|
+
},
|
|
478
|
+
{
|
|
479
|
+
code: 'class A { @property({type: Boolean}) accessor onHold = false; }',
|
|
480
|
+
errors: 1,
|
|
481
|
+
},
|
|
482
|
+
],
|
|
483
|
+
}
|
|
484
|
+
);
|
|
485
|
+
});
|
|
486
|
+
});
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import {PropertyValues} from 'lit';
|
|
1
2
|
import {property} from 'lit/decorators.js';
|
|
2
3
|
import {ObcAbstractAutomationButton} from '../automation-button/abstract-automation-button.js';
|
|
3
4
|
import {
|
|
@@ -26,10 +27,18 @@ export enum MotorizedVariant {
|
|
|
26
27
|
* Not registered as a custom element. `obc-fan`, `obc-motor` and `obc-pump`
|
|
27
28
|
* extend it and supply their own `icon` and `variant`.
|
|
28
29
|
*
|
|
30
|
+
* @property turnedOn - Whether the device is running. Selects the running
|
|
31
|
+
* icon and the speed readout instead of the `Off` state. Not named `on`,
|
|
32
|
+
* which Svelte binds as an event listener in markup (#1090).
|
|
33
|
+
* @property on - Alias of `turnedOn` for 1.x markup: setting it sets
|
|
34
|
+
* `turnedOn`.
|
|
29
35
|
* @availableWhen direction variant in [double, forward, flatForward]
|
|
30
36
|
*/
|
|
31
37
|
export class ObcAbstractAutomationButtonMotorized extends ObcAbstractAutomationButton {
|
|
32
|
-
@property({type: Boolean})
|
|
38
|
+
@property({type: Boolean}) turnedOn: boolean = false;
|
|
39
|
+
/** @deprecated Use `turnedOn`. */
|
|
40
|
+
// eslint-disable-next-line openbridge/no-event-like-property-name -- deprecated alias kept for 1.x markup (#1090)
|
|
41
|
+
@property({type: Boolean}) on?: boolean;
|
|
33
42
|
/**
|
|
34
43
|
* @deprecated Use `speed` together with `speedUnit` instead. When `speed`
|
|
35
44
|
* is set it takes precedence over `speedInPercent`.
|
|
@@ -50,7 +59,7 @@ export class ObcAbstractAutomationButtonMotorized extends ObcAbstractAutomationB
|
|
|
50
59
|
if (!this.showStatus) {
|
|
51
60
|
return [];
|
|
52
61
|
}
|
|
53
|
-
if (speed !== undefined && speed !== null && this.
|
|
62
|
+
if (speed !== undefined && speed !== null && this.turnedOn) {
|
|
54
63
|
return [
|
|
55
64
|
{
|
|
56
65
|
type: 'value',
|
|
@@ -64,7 +73,7 @@ export class ObcAbstractAutomationButtonMotorized extends ObcAbstractAutomationB
|
|
|
64
73
|
: 'chevron',
|
|
65
74
|
},
|
|
66
75
|
];
|
|
67
|
-
} else if (!this.
|
|
76
|
+
} else if (!this.turnedOn) {
|
|
68
77
|
return [
|
|
69
78
|
{
|
|
70
79
|
type: 'state-off',
|
|
@@ -76,7 +85,14 @@ export class ObcAbstractAutomationButtonMotorized extends ObcAbstractAutomationB
|
|
|
76
85
|
return [];
|
|
77
86
|
}
|
|
78
87
|
|
|
88
|
+
override willUpdate(changed: PropertyValues<this>): void {
|
|
89
|
+
super.willUpdate(changed);
|
|
90
|
+
if (changed.has('on') && this.on !== undefined) {
|
|
91
|
+
this.turnedOn = this.on;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
|
|
79
95
|
override get _on(): boolean {
|
|
80
|
-
return this.
|
|
96
|
+
return this.turnedOn;
|
|
81
97
|
}
|
|
82
98
|
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import {PropertyValues} from 'lit';
|
|
1
2
|
import {property} from 'lit/decorators.js';
|
|
2
3
|
import {ObcAbstractAutomationButton} from './abstract-automation-button.js';
|
|
3
4
|
import {AutomationButtonReadoutStack} from '../../components/automation-button-readout-stack/automation-button-readout-stack.js';
|
|
@@ -8,8 +9,30 @@ export enum SquaredVariant {
|
|
|
8
9
|
flat = 'flat',
|
|
9
10
|
}
|
|
10
11
|
|
|
12
|
+
/**
|
|
13
|
+
* Base class for two-state automation buttons.
|
|
14
|
+
*
|
|
15
|
+
* Extends `ObcAbstractAutomationButton` with the on/off state: the subclass
|
|
16
|
+
* picks its icon from `turnedOn`, and the readout adds the `On` or `Off`
|
|
17
|
+
* state row.
|
|
18
|
+
*
|
|
19
|
+
* ## Usage Guidelines
|
|
20
|
+
*
|
|
21
|
+
* Not registered as a custom element. `obc-switch`, `obc-converter`,
|
|
22
|
+
* `obc-diodes` and the other two-state devices extend it and supply their own
|
|
23
|
+
* `icon`.
|
|
24
|
+
*
|
|
25
|
+
* @property turnedOn - Whether the device is on. Selects the on icon and the
|
|
26
|
+
* `On` state row instead of `Off`. Not named `on`, which Svelte binds as an
|
|
27
|
+
* event listener in markup (#1090).
|
|
28
|
+
* @property on - Alias of `turnedOn` for 1.x markup: setting it sets
|
|
29
|
+
* `turnedOn`.
|
|
30
|
+
*/
|
|
11
31
|
export class ObcAbstractAutomationButtonSquared extends ObcAbstractAutomationButton {
|
|
12
|
-
@property({type: Boolean})
|
|
32
|
+
@property({type: Boolean}) turnedOn: boolean = false;
|
|
33
|
+
/** @deprecated Use `turnedOn`. */
|
|
34
|
+
// eslint-disable-next-line openbridge/no-event-like-property-name -- deprecated alias kept for 1.x markup (#1090)
|
|
35
|
+
@property({type: Boolean}) on?: boolean;
|
|
13
36
|
@property({type: String}) variant: SquaredVariant = SquaredVariant.square;
|
|
14
37
|
@property({type: String}) orientation: AutomationButtonOrientation =
|
|
15
38
|
AutomationButtonOrientation.horizontal;
|
|
@@ -22,7 +45,7 @@ export class ObcAbstractAutomationButtonSquared extends ObcAbstractAutomationBut
|
|
|
22
45
|
if (!this.showStatus) {
|
|
23
46
|
return [];
|
|
24
47
|
}
|
|
25
|
-
if (this.
|
|
48
|
+
if (this.turnedOn) {
|
|
26
49
|
return [
|
|
27
50
|
{
|
|
28
51
|
type: 'state-on',
|
|
@@ -41,7 +64,14 @@ export class ObcAbstractAutomationButtonSquared extends ObcAbstractAutomationBut
|
|
|
41
64
|
}
|
|
42
65
|
}
|
|
43
66
|
|
|
67
|
+
override willUpdate(changed: PropertyValues<this>): void {
|
|
68
|
+
super.willUpdate(changed);
|
|
69
|
+
if (changed.has('on') && this.on !== undefined) {
|
|
70
|
+
this.turnedOn = this.on;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
44
74
|
override get _on(): boolean {
|
|
45
|
-
return this.
|
|
75
|
+
return this.turnedOn;
|
|
46
76
|
}
|
|
47
77
|
}
|
|
@@ -88,6 +88,7 @@ export const argTypesAbstractAutomationButtonPassiveRound = {
|
|
|
88
88
|
|
|
89
89
|
export const argTypesAbstractAutomationButtonPassiveSquare = {
|
|
90
90
|
...argTypesAbstractAutomationButton,
|
|
91
|
+
on: {table: {disable: true}, control: false},
|
|
91
92
|
variant: {
|
|
92
93
|
options: ['square', 'flat'],
|
|
93
94
|
control: {type: 'radio'},
|
|
@@ -100,6 +101,7 @@ export const argTypesAbstractAutomationButtonPassiveSquare = {
|
|
|
100
101
|
|
|
101
102
|
export const argTypesAbstractAutomationButtonMotorized = {
|
|
102
103
|
...argTypesAbstractAutomationButton,
|
|
104
|
+
on: {table: {disable: true}, control: false},
|
|
103
105
|
speedInPercent: {
|
|
104
106
|
control: {type: 'range', min: 0, max: 100, step: 1},
|
|
105
107
|
description: 'Deprecated, use `speed` together with `speedUnit` instead.',
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import {describe, it, expect, afterEach} from 'vitest';
|
|
2
|
+
import '../pump/pump.js';
|
|
3
|
+
import '../switch/switch.js';
|
|
4
|
+
import type {ObcPump} from '../pump/pump.js';
|
|
5
|
+
import type {ObcSwitch} from '../switch/switch.js';
|
|
6
|
+
import {AutomationButtonState} from './automation-button.js';
|
|
7
|
+
|
|
8
|
+
type Device = ObcPump | ObcSwitch;
|
|
9
|
+
|
|
10
|
+
const mounted: HTMLElement[] = [];
|
|
11
|
+
afterEach(() => mounted.splice(0).forEach((el) => el.remove()));
|
|
12
|
+
|
|
13
|
+
async function mount(tag: string, configure: (el: Device) => void) {
|
|
14
|
+
const el = document.createElement(tag) as Device;
|
|
15
|
+
configure(el);
|
|
16
|
+
document.body.appendChild(el);
|
|
17
|
+
mounted.push(el);
|
|
18
|
+
await el.updateComplete;
|
|
19
|
+
return el;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
const state = (el: Device) =>
|
|
23
|
+
(
|
|
24
|
+
el.shadowRoot!.querySelector('obc-automation-button') as unknown as {
|
|
25
|
+
state: AutomationButtonState;
|
|
26
|
+
}
|
|
27
|
+
).state;
|
|
28
|
+
|
|
29
|
+
describe.each(['obc-pump', 'obc-switch'])('%s turnedOn', (tag) => {
|
|
30
|
+
it('turns the device on', async () => {
|
|
31
|
+
const el = await mount(tag, (e) => {
|
|
32
|
+
e.turnedOn = true;
|
|
33
|
+
});
|
|
34
|
+
expect(state(el)).toBe(AutomationButtonState.open);
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
it('keeps the 1.x `on` attribute working on the first render', async () => {
|
|
38
|
+
const el = await mount(tag, (e) => e.setAttribute('on', ''));
|
|
39
|
+
expect(el.turnedOn).toBe(true);
|
|
40
|
+
expect(state(el)).toBe(AutomationButtonState.open);
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
it('follows `on` when it is set or removed later', async () => {
|
|
44
|
+
const el = await mount(tag, (e) => e.setAttribute('on', ''));
|
|
45
|
+
el.removeAttribute('on');
|
|
46
|
+
await el.updateComplete;
|
|
47
|
+
expect(el.turnedOn).toBe(false);
|
|
48
|
+
el.on = true;
|
|
49
|
+
await el.updateComplete;
|
|
50
|
+
expect(state(el)).toBe(AutomationButtonState.open);
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
// The generated Vue wrapper writes every prop's creation-time value back on
|
|
54
|
+
// its second render; for `on` that value is undefined.
|
|
55
|
+
it('leaves turnedOn alone when `on` is written back unset', async () => {
|
|
56
|
+
const el = await mount(tag, (e) => {
|
|
57
|
+
e.turnedOn = true;
|
|
58
|
+
});
|
|
59
|
+
el.on = undefined;
|
|
60
|
+
await el.updateComplete;
|
|
61
|
+
expect(el.turnedOn).toBe(true);
|
|
62
|
+
expect(state(el)).toBe(AutomationButtonState.open);
|
|
63
|
+
});
|
|
64
|
+
});
|