Skip to content

Commit 1bdc31a

Browse files
authored
fix(accordion): remove animation (#2598)
fixes #2597
1 parent 45a1a27 commit 1bdc31a

File tree

5 files changed

+11
-84
lines changed

5 files changed

+11
-84
lines changed

.changeset/accordion-no-animate.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
---
2+
"@patternfly/elements": patch
3+
---
4+
`<pf-accordion>`: remove animations which are not present in PatternFly specs

docs/main.css

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ main.blog {
2626
opacity: 0;
2727
}
2828

29-
:defined {
29+
/* exclude demos */
30+
[class^="layout-"] :defined {
3031
transition: opacity 0.2s ease;
3132
}
3233

elements/pf-accordion/BaseAccordion.css

Lines changed: 0 additions & 5 deletions
This file was deleted.

elements/pf-accordion/BaseAccordion.ts

Lines changed: 5 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,6 @@ import { BaseAccordionPanel } from './BaseAccordionPanel.js';
1111

1212
import { RovingTabindexController } from '@patternfly/pfe-core/controllers/roving-tabindex-controller.js';
1313

14-
import style from './BaseAccordion.css';
15-
16-
const CSS_TIMING_UNITS_RE = /^[0-9.]+(?<unit>[a-zA-Z]+)/g;
17-
1814
export class AccordionExpandEvent extends ComposedEvent {
1915
constructor(
2016
public toggle: BaseAccordionHeader,
@@ -34,7 +30,7 @@ export class AccordionCollapseEvent extends ComposedEvent {
3430
}
3531

3632
export abstract class BaseAccordion extends LitElement {
37-
static readonly styles = [style];
33+
static readonly styles = [];
3834

3935
static isAccordion(target: EventTarget | null): target is BaseAccordion {
4036
return target instanceof BaseAccordion;
@@ -104,10 +100,6 @@ export abstract class BaseAccordion extends LitElement {
104100

105101
#logger = new Logger(this);
106102

107-
#styles = getComputedStyle(this);
108-
109-
#transitionDuration = this.#getAnimationDuration();
110-
111103
// actually is read in #init, by the `||=` operator
112104
#initialized = false;
113105

@@ -158,11 +150,11 @@ export abstract class BaseAccordion extends LitElement {
158150
this.#initialized ||= !!await this.updateComplete;
159151
this.#headerIndex.initItems(this.headers);
160152
// Event listener to the accordion header after the accordion has been initialized to add the roving tabindex
161-
this.addEventListener('focusin', this.#updateActiveHeader as EventListener);
153+
this.addEventListener('focusin', this.#updateActiveHeader);
162154
this.updateAccessibility();
163155
}
164156

165-
#updateActiveHeader(event: FocusEvent) {
157+
#updateActiveHeader() {
166158
if (this.#activeHeader) {
167159
this.#headerIndex.updateActiveItem(this.#activeHeader);
168160
}
@@ -184,15 +176,9 @@ export abstract class BaseAccordion extends LitElement {
184176
header.expanded = true;
185177
}
186178

187-
async #expandPanel(panel: BaseAccordionPanel) {
179+
#expandPanel(panel: BaseAccordionPanel) {
188180
panel.expanded = true;
189181
panel.hidden = false;
190-
191-
await panel.updateComplete;
192-
193-
const rect = panel.getBoundingClientRect();
194-
195-
this.#animate(panel, 0, rect.height);
196182
}
197183

198184
async #collapseHeader(header: BaseAccordionHeader, index = this.#getIndex(header)) {
@@ -210,66 +196,12 @@ export abstract class BaseAccordion extends LitElement {
210196
return;
211197
}
212198

213-
const rect = panel.getBoundingClientRect();
214-
215199
panel.expanded = false;
216200
panel.hidden = true;
217-
218-
this.#animate(panel, rect.height, 0);
219-
await panel.updateComplete;
220-
}
221-
222-
#getAnimationDuration(): number {
223-
if ('computedStyleMap' in this) {
224-
// @ts-expect-error: https://caniuse.com/?search=computedStyleMap
225-
return this.computedStyleMap().get('transition-duration')?.to('ms').value;
226-
} else {
227-
const { transitionDuration } = this.#styles;
228-
229-
const groups = CSS_TIMING_UNITS_RE.exec(transitionDuration)?.groups;
230-
231-
if (!groups) {
232-
return 0;
233-
}
234-
235-
const parsed = parseFloat(transitionDuration);
236-
237-
if (groups.unit === 's') {
238-
return parsed * 1000;
239-
} else {
240-
return parsed;
241-
}
242-
}
243-
}
244-
245-
async #animate(panel: BaseAccordionPanel, start: number, end: number) {
246-
if (panel) {
247-
const header = panel.previousElementSibling;
248-
249-
const transitionDuration = this.#getAnimationDuration();
250-
if (transitionDuration) {
251-
this.#transitionDuration = transitionDuration;
252-
}
253-
254-
const duration = this.#transitionDuration ?? 0;
255-
256-
header?.classList.add('animating');
257-
panel.classList.add('animating');
258-
259-
const animation = panel.animate({ height: [`${start}px`, `${end}px`] }, { duration });
260-
animation.play();
261-
await animation.finished;
262-
263-
header?.classList.remove('animating');
264-
panel.classList.remove('animating');
265-
266-
panel.style.removeProperty('height');
267-
panel.hidden = !panel.expanded;
268-
}
269201
}
270202

271203
#onChange(event: AccordionHeaderChangeEvent) {
272-
if (BaseAccordion.#isAccordionChangeEvent(event) && !this.classList.contains('animating')) {
204+
if (BaseAccordion.#isAccordionChangeEvent(event)) {
273205
const index = this.#getIndex(event.target);
274206
if (event.expanded) {
275207
this.expand(index, event.accordion);

elements/pf-accordion/BaseAccordionPanel.css

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,6 @@
99
position: relative;
1010
}
1111

12-
:host(.animating) {
13-
display: block;
14-
transition: height 0.3s ease-in-out;
15-
}
16-
1712
:host([fixed]) {
1813
overflow-y: auto;
1914
}

0 commit comments

Comments
 (0)