Skip to content

Commit bb320ef

Browse files
fix(accordion): fixed animated height calculation for keyframes
1 parent a6a213b commit bb320ef

File tree

7 files changed

+53
-42
lines changed

7 files changed

+53
-42
lines changed

apps/website/src/global.css

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,39 @@
1212
--light-color-bg: rgb(203 213 225);
1313
--light-color-text: #333;
1414

15+
@font-face {
16+
font-family: 'Poppins';
17+
font-style: normal;
18+
font-weight: 400;
19+
font-display: swap;
20+
src: url('/fonts/poppins-400.woff2') format('woff2');
21+
unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA,
22+
U+02DC, U+0300-0301, U+0303-0304, U+0308-0309, U+0323, U+0329, U+2000-206F,
23+
U+2074, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
24+
}
25+
26+
@font-face {
27+
font-family: 'Poppins';
28+
font-style: normal;
29+
font-weight: 500;
30+
font-display: swap;
31+
src: url('/fonts/poppins-500.woff2') format('woff2');
32+
unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA,
33+
U+02DC, U+0300-0301, U+0303-0304, U+0308-0309, U+0323, U+0329, U+2000-206F,
34+
U+2074, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
35+
}
36+
37+
@font-face {
38+
font-family: 'Poppins';
39+
font-style: normal;
40+
font-weight: 700;
41+
font-display: swap;
42+
src: url('/fonts/poppins-700.woff2') format('woff2');
43+
unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA,
44+
U+02DC, U+0300-0301, U+0303-0304, U+0308-0309, U+0323, U+0329, U+2000-206F,
45+
U+2074, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
46+
}
47+
1548
--shadow-color: 0deg 0% 63%;
1649
--shadow-elevation-low: 0.5px 0.6px 0.9px hsl(var(--shadow-color) / 0.34),
1750
0.9px 1px 1.5px -1.2px hsl(var(--shadow-color) / 0.34),

apps/website/src/routes/layout-landing.tsx

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,6 @@ import { OLD_APP_STATE_CONTEXT_ID } from '../constants';
1111

1212
import { Footer } from '../components/footer/footer';
1313

14-
import '@fontsource/poppins/100.css';
15-
import '@fontsource/poppins/200.css';
16-
import '@fontsource/poppins/300.css';
17-
import '@fontsource/poppins/400.css';
18-
import '@fontsource/poppins/500.css';
19-
import '@fontsource/poppins/600.css';
20-
import '@fontsource/poppins/700.css';
21-
import '@fontsource/poppins/800.css';
22-
import '@fontsource/poppins/900.css';
23-
2414
export default component$(() => {
2515
// useStyles$(globalStyles);
2616

apps/website/src/routes/layout.tsx

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,6 @@ import {
1313
} from '../_state/component-statuses';
1414
import Header from '../components/header/header';
1515

16-
// proper self-hosting of fonts at built
17-
import '@fontsource/poppins/100.css';
18-
import '@fontsource/poppins/200.css';
19-
import '@fontsource/poppins/300.css';
20-
import '@fontsource/poppins/400.css';
21-
import '@fontsource/poppins/500.css';
22-
import '@fontsource/poppins/600.css';
23-
import '@fontsource/poppins/700.css';
24-
import '@fontsource/poppins/800.css';
25-
import '@fontsource/poppins/900.css';
26-
2716
export default component$(() => {
2817
useStyles$(prismStyles);
2918
useStyles$(docsStyles);

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,6 @@
115115
"components library"
116116
],
117117
"dependencies": {
118-
"@fontsource/poppins": "5.0.5",
119118
"tslib": "^2.3.0"
120119
}
121120
}

packages/kit-headless/src/components/accordion/accordion-content.tsx

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,19 @@ export type ContentProps = QwikIntrinsicElements['div'];
2121

2222
export const AccordionContent = component$(({ ...props }: ContentProps) => {
2323
const contextService = useContext(accordionRootContextId);
24+
const itemContext = useContext(accordionItemContextId);
25+
2426
const ref = useSignal<HTMLElement>();
2527
const contentElement = ref.value;
26-
const itemContext = useContext(accordionItemContextId);
2728
const contentId = `${itemContext.itemId}-content`;
28-
const isTriggerExpandedSig = itemContext.isTriggerExpandedSig;
29-
const isContentHiddenSig = useSignal<boolean>(true);
29+
3030
const animated = contextService.animated;
31+
const defaultValue = itemContext.defaultValue;
3132
const totalHeightSig = useSignal<number>(0);
3233

34+
const isTriggerExpandedSig = itemContext.isTriggerExpandedSig;
35+
const isContentHiddenSig = useSignal<boolean>(!defaultValue);
36+
3337
const hideContent$ = $(() => {
3438
if (!isTriggerExpandedSig.value) {
3539
isContentHiddenSig.value = true;
@@ -41,6 +45,10 @@ export const AccordionContent = component$(({ ...props }: ContentProps) => {
4145
overflow: hidden;
4246
}
4347
48+
[data-state="open"] {
49+
display: block;
50+
}
51+
4452
/* check global.css utilites layer for animation */
4553
@keyframes accordion-open {
4654
0% {
@@ -71,13 +79,18 @@ export const AccordionContent = component$(({ ...props }: ContentProps) => {
7179
});
7280

7381
/* calculates height of the content container based on children */
74-
useVisibleTask$(function calculateHeightVisibleTask() {
75-
if (animated) {
76-
totalHeightSig.value = 0;
82+
useVisibleTask$(function calculateHeightVisibleTask({ track }) {
83+
track(() => isContentHiddenSig.value);
7784

85+
if (animated && totalHeightSig.value === 0) {
86+
getCalculatedHeight();
87+
}
88+
89+
function getCalculatedHeight() {
7890
const contentChildren = Array.from(
7991
contentElement?.children!
8092
) as HTMLElement[];
93+
8194
contentChildren.forEach((element, index) => {
8295
totalHeightSig.value += element.offsetHeight;
8396

packages/kit-headless/src/components/accordion/accordion-item.tsx

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,7 @@ export const AccordionItem = component$(
2020
const itemId = useId();
2121

2222
const itemRef = useSignal<HTMLElement>();
23-
const isTriggerExpandedSig = useSignal<boolean>(
24-
defaultValue ? true : false
25-
);
26-
console.log(isTriggerExpandedSig.value);
23+
const isTriggerExpandedSig = useSignal<boolean>(defaultValue);
2724

2825
const itemContext: AccordionItemContext = {
2926
itemId,

pnpm-lock.yaml

Lines changed: 0 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)