Skip to content

Commit 91cf153

Browse files
committed
fix(progress): use @observes instead of willUpdate
1 parent a4aca6c commit 91cf153

1 file changed

Lines changed: 42 additions & 31 deletions

File tree

elements/pf-v6-progress/pf-v6-progress.ts

Lines changed: 42 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1-
import type { PropertyValues, TemplateResult } from 'lit';
1+
import type { TemplateResult } from 'lit';
22
import { LitElement, html, nothing, isServer } from 'lit';
33
import { customElement } from 'lit/decorators/custom-element.js';
44
import { property } from 'lit/decorators/property.js';
55
import { classMap } from 'lit/directives/class-map.js';
66
import { styleMap } from 'lit/directives/style-map.js';
77

8+
import { observes } from '@patternfly/pfe-core/decorators/observes.js';
89
import { InternalsController } from '@patternfly/pfe-core/controllers/internals-controller.js';
910
import { SlotController } from '@patternfly/pfe-core/controllers/slot-controller.js';
1011

@@ -120,40 +121,50 @@ export class PfV6Progress extends LitElement {
120121
return VARIANT_ICONS.get(this.variant!) ?? nothing;
121122
}
122123

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;
151147
}
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;
154159
}
155160
}
156161

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+
157168
override render(): TemplateResult<1> {
158169
const pct = this.#calculatedPercentage;
159170
const displayText = this.#displayText;

0 commit comments

Comments
 (0)