|
1 | | -import type { PropertyValues, TemplateResult } from 'lit'; |
| 1 | +import type { TemplateResult } from 'lit'; |
2 | 2 | import { LitElement, html, nothing, isServer } from 'lit'; |
3 | 3 | import { customElement } from 'lit/decorators/custom-element.js'; |
4 | 4 | import { property } from 'lit/decorators/property.js'; |
5 | 5 | import { classMap } from 'lit/directives/class-map.js'; |
6 | 6 | import { styleMap } from 'lit/directives/style-map.js'; |
7 | 7 |
|
| 8 | +import { observes } from '@patternfly/pfe-core/decorators/observes.js'; |
8 | 9 | import { InternalsController } from '@patternfly/pfe-core/controllers/internals-controller.js'; |
9 | 10 | import { SlotController } from '@patternfly/pfe-core/controllers/slot-controller.js'; |
10 | 11 |
|
@@ -120,40 +121,50 @@ export class PfV6Progress extends LitElement { |
120 | 121 | return VARIANT_ICONS.get(this.variant!) ?? nothing; |
121 | 122 | } |
122 | 123 |
|
123 | | - override willUpdate(changed: PropertyValues<this>): void { |
124 | | - if (changed.has('value') || changed.has('min') || changed.has('max')) { |
125 | | - this.#internals.ariaValueNow = this.#calculatedPercentage.toString(); |
126 | | - this.#internals.ariaValueMin = '0'; |
127 | | - this.#internals.ariaValueMax = '100'; |
128 | | - } |
129 | | - if (changed.has('valueText')) { |
130 | | - this.#internals.ariaValueText = this.valueText ?? null; |
131 | | - } |
132 | | - if (changed.has('accessibleLabelledby')) { |
133 | | - if (!isServer && this.accessibleLabelledby) { |
134 | | - const elements = this.accessibleLabelledby.trim().split(/\s+/) |
135 | | - .map(id => document.getElementById(id)) |
136 | | - .filter((el): el is Element => el != null); |
137 | | - this.#internals.ariaLabelledByElements = elements.length ? elements : null; |
138 | | - } else { |
139 | | - this.#internals.ariaLabelledByElements = null; |
140 | | - } |
141 | | - } |
142 | | - if (changed.has('accessibleDescribedby')) { |
143 | | - if (!isServer && this.accessibleDescribedby) { |
144 | | - const elements = this.accessibleDescribedby.trim().split(/\s+/) |
145 | | - .map(id => document.getElementById(id)) |
146 | | - .filter((el): el is Element => el != null); |
147 | | - this.#internals.ariaDescribedByElements = elements.length ? elements : null; |
148 | | - } else { |
149 | | - this.#internals.ariaDescribedByElements = null; |
150 | | - } |
| 124 | + @observes('value') |
| 125 | + @observes('min') |
| 126 | + @observes('max') |
| 127 | + private _updateAriaValue() { |
| 128 | + this.#internals.ariaValueNow = this.#calculatedPercentage.toString(); |
| 129 | + this.#internals.ariaValueMin = '0'; |
| 130 | + this.#internals.ariaValueMax = '100'; |
| 131 | + } |
| 132 | + |
| 133 | + @observes('valueText') |
| 134 | + private _updateAriaValueText() { |
| 135 | + this.#internals.ariaValueText = this.valueText ?? null; |
| 136 | + } |
| 137 | + |
| 138 | + @observes('accessibleLabelledby', { waitFor: 'connected' }) |
| 139 | + private _updateAriaLabelledBy() { |
| 140 | + if (!isServer && this.accessibleLabelledby) { |
| 141 | + const elements = this.accessibleLabelledby.trim().split(/\s+/) |
| 142 | + .map(id => document.getElementById(id)) |
| 143 | + .filter((el): el is HTMLElement => el != null); |
| 144 | + this.#internals.ariaLabelledByElements = elements.length ? elements : null; |
| 145 | + } else { |
| 146 | + this.#internals.ariaLabelledByElements = null; |
151 | 147 | } |
152 | | - if (changed.has('accessibleLabel') || changed.has('description') || !this.hasUpdated) { |
153 | | - this.#internals.ariaLabel = this.accessibleLabel ?? this.description ?? 'Progress status'; |
| 148 | + } |
| 149 | + |
| 150 | + @observes('accessibleDescribedby', { waitFor: 'connected' }) |
| 151 | + private _updateAriaDescribedBy() { |
| 152 | + if (!isServer && this.accessibleDescribedby) { |
| 153 | + const elements = this.accessibleDescribedby.trim().split(/\s+/) |
| 154 | + .map(id => document.getElementById(id)) |
| 155 | + .filter((el): el is HTMLElement => el != null); |
| 156 | + this.#internals.ariaDescribedByElements = elements.length ? elements : null; |
| 157 | + } else { |
| 158 | + this.#internals.ariaDescribedByElements = null; |
154 | 159 | } |
155 | 160 | } |
156 | 161 |
|
| 162 | + @observes('accessibleLabel', { waitFor: 'connected' }) |
| 163 | + @observes('description', { waitFor: 'connected' }) |
| 164 | + private _updateAriaLabel() { |
| 165 | + this.#internals.ariaLabel = this.accessibleLabel ?? this.description ?? 'Progress status'; |
| 166 | + } |
| 167 | + |
157 | 168 | override render(): TemplateResult<1> { |
158 | 169 | const pct = this.#calculatedPercentage; |
159 | 170 | const displayText = this.#displayText; |
|
0 commit comments