@clicktap/ui 2.4.4 → 2.4.5
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.
|
@@ -1,19 +1,4 @@
|
|
|
1
1
|
import { ComponentType, ReactNode } from 'react';
|
|
2
|
-
/**
|
|
3
|
-
* Native accordion on react-aria-components Disclosure (CTAP-1383).
|
|
4
|
-
*
|
|
5
|
-
* Previously a styled wrapper around @heroui/accordion — the ONLY
|
|
6
|
-
* initially-rendered @heroui consumer (the PLP filter sidebar), which pulled
|
|
7
|
-
* the whole @heroui system + theme (~25 KiB gz) into every page's initial JS.
|
|
8
|
-
* react-aria-components is already this library's base, so the rewrite costs
|
|
9
|
-
* nothing new. API-compatible with the call sites this repo uses:
|
|
10
|
-
* selectionMode / defaultSelectedKeys ("all" included), per-item title,
|
|
11
|
-
* subtitle, startContent, indicator (component, receives nothing, rotates on
|
|
12
|
-
* open), classNames slots, showDivider (an <hr> between items — consumers
|
|
13
|
-
* hide it with [&_hr]:hidden), onPress, and the `data-open` attribute on
|
|
14
|
-
* heading/trigger/indicator that consumers style with data-[open=true]:.
|
|
15
|
-
* Height animates with the CSS grid-rows trick — no animation runtime.
|
|
16
|
-
*/
|
|
17
2
|
type ItemSlotClassNames = {
|
|
18
3
|
base?: string;
|
|
19
4
|
heading?: string;
|
|
@@ -38,6 +23,8 @@ export type AccordionItemProps = {
|
|
|
38
23
|
hideIndicator?: boolean;
|
|
39
24
|
disableIndicatorAnimation?: boolean;
|
|
40
25
|
isDisabled?: boolean;
|
|
26
|
+
/** Overrides the Accordion's keepContentMounted for this item. */
|
|
27
|
+
keepContentMounted?: boolean;
|
|
41
28
|
textValue?: string;
|
|
42
29
|
'aria-label'?: string;
|
|
43
30
|
classNames?: ItemSlotClassNames;
|
|
@@ -53,6 +40,10 @@ export type AccordionProps = {
|
|
|
53
40
|
selectedKeys?: 'all' | Iterable<string>;
|
|
54
41
|
onSelectionChange?: (keys: Set<string>) => void;
|
|
55
42
|
disallowEmptySelection?: boolean;
|
|
43
|
+
/**
|
|
44
|
+
* Keep every collapsed item's content mounted (and server-rendered). Off by
|
|
45
|
+
* default: a collapsed item renders its content only while expanded.
|
|
46
|
+
*/
|
|
56
47
|
keepContentMounted?: boolean;
|
|
57
48
|
/** Hide every item's indicator (heroui group-level prop). */
|
|
58
49
|
hideIndicator?: boolean;
|
|
@@ -73,6 +64,6 @@ export type AccordionProps = {
|
|
|
73
64
|
* did not change.
|
|
74
65
|
*/
|
|
75
66
|
export declare function AccordionItem(_props: AccordionItemProps): null;
|
|
76
|
-
export declare function Accordion({ children, selectionMode, defaultSelectedKeys, defaultExpandedKeys, selectedKeys, onSelectionChange, disallowEmptySelection, hideIndicator: groupHideIndicator, showDivider, dividerProps, variant, isCompact, className, itemClasses, }: AccordionProps): import("react/jsx-runtime").JSX.Element;
|
|
67
|
+
export declare function Accordion({ children, selectionMode, defaultSelectedKeys, defaultExpandedKeys, selectedKeys, onSelectionChange, disallowEmptySelection, keepContentMounted: groupKeepContentMounted, hideIndicator: groupHideIndicator, showDivider, dividerProps, variant, isCompact, className, itemClasses, }: AccordionProps): import("react/jsx-runtime").JSX.Element;
|
|
77
68
|
export default Accordion;
|
|
78
69
|
export declare function AccordionItemArrow(): import("react/jsx-runtime").JSX.Element;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use client";import{jsx as e,jsxs as
|
|
1
|
+
"use client";import{jsx as e,jsxs as b,Fragment as G}from"react/jsx-runtime";import{Children as V,isValidElement as q,Fragment as H,useState as D,useEffect as J}from"react";import{DisclosureGroup as Q,Disclosure as R,Button as U,DisclosurePanel as X}from"react-aria-components";import{cn as r}from"../../utils/cn.js";import{DownArrow as M}from"../Icon/DownArrow.js";const Y=200;function oe(n){return null}function le({children:n,selectionMode:f="single",defaultSelectedKeys:m,defaultExpandedKeys:h,selectedKeys:d,onSelectionChange:c,disallowEmptySelection:g=!1,keepContentMounted:y=!1,hideIndicator:s=!1,showDivider:K=!0,dividerProps:P,variant:u,isCompact:p,className:T,itemClasses:o}){const x=V.toArray(n).filter(q),w=(t,a)=>String(t.key??a).replace(/^\.\$/,"").replace(/=2/g,":").replace(/=0/g,"="),F=x.map(w),k=t=>t==="all"?F:t?[...t].map(String):void 0,W=k(m??h)??[],j=k(d);return e(Q,{allowsMultipleExpanded:f==="multiple",defaultExpandedKeys:W,expandedKeys:j,onExpandedChange:t=>{const a=new Set([...t].map(String));g&&a.size===0||c?.(a)},className:r("px-0",u==="bordered"&&["px-4 py-4 rounded-xl border-2 border-border-subtle"],u==="shadow"&&["px-4 py-4 rounded-xl bg-surface-subtle border border-border-subtle"],T),children:x.map((t,a)=>{const A=w(t,a),{title:L,subtitle:S,startContent:I,indicator:N,hideIndicator:O,disableIndicatorAnimation:v,isDisabled:_,keepContentMounted:$,classNames:l,onPress:z,children:B}=t.props;return b(H,{children:[e(R,{id:A,isDisabled:_,className:r("w-full py-2","data-disabled:pointer-events-none data-disabled:opacity-50",u==="bordered"&&["rounded-xl py-0"],u==="splitted"&&["flex flex-col bg-surface-subtle rounded-xl border border-border-subtle"],p&&"py-0",o?.base,l?.base),children:({isExpanded:i})=>b(G,{children:[e("h2",{"data-open":i||void 0,className:r(o?.heading,l?.heading),children:b(U,{slot:"trigger","data-open":i||void 0,onPress:z,"aria-label":t.props["aria-label"],className:r("w-full h-full flex items-center gap-3 py-0 appearance-none cursor-pointer select-none","border-0 focus-visible:outline-2 focus-visible:outline focus-visible:outline-border-subtle","bg-transparent text-inherit",p&&["py-2"],o?.trigger,l?.trigger),children:[I!=null&&e("span",{className:r("shrink-0",o?.startContent,l?.startContent),children:I}),b("span",{className:r("flex-1 text-left",o?.titleWrapper,l?.titleWrapper),children:[e("span",{className:r("block text-xl font-semibold",p&&"text-base",o?.title,l?.title),children:L}),S!=null&&e("span",{className:r("block text-base",p&&"text-sm",o?.subtitle,l?.subtitle),children:S})]}),O||s?null:e("span",{"aria-hidden":"true","data-open":i||void 0,className:r("shrink-0",!v&&"transition-transform duration-200",!v&&i&&"-rotate-180",o?.indicator,l?.indicator),children:typeof N=="function"?e(N,{isOpen:i}):N??e(M,{className:"w-4 h-4"})})]})}),e(Z,{isExpanded:i,keepContentMounted:$??y,className:r(p?"py-1":"py-2",o?.content,l?.content),children:B})]})}),K&&a<x.length-1&&e("hr",{className:r("border-solid border-b-0 border-x-0",P?.className??["my-2 border-border-subtle",u==="shadow"&&"border-border"])})]},A)})})}function Z({isExpanded:n,keepContentMounted:f,className:m,children:h}){const[d,c]=D(!1),[g,y]=D(n);return g!==n&&(y(n),c(!n)),J(()=>{if(!d)return;const s=setTimeout(()=>c(!1),Y+50);return()=>clearTimeout(s)},[d]),e("div",{className:r("grid transition-[grid-template-rows] duration-200 ease-in-out",n?"grid-rows-[1fr]":"grid-rows-[0fr]"),onTransitionEnd:s=>{s.target===s.currentTarget&&!n&&c(!1)},children:e("div",{className:"overflow-hidden min-h-0",children:e(X,{className:m,children:f||n||d?h:null})})})}function ae(){return e(M,{className:"w-4 h-4"})}export{le as Accordion,oe as AccordionItem,ae as AccordionItemArrow,le as default};
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
# `Accordion` mounts a collapsed item's content only when it expands
|
|
2
|
+
|
|
3
|
+
**Date:** 2026-10-06
|
|
4
|
+
**Package:** `@clicktap/ui`
|
|
5
|
+
**Affects:** `components/Accordion` (`Accordion`, `AccordionItem`)
|
|
6
|
+
**Classification:** BUGFIX
|
|
7
|
+
**Breaking:** No API change. ⚠️ Behavior change for any consumer that relies on collapsed content being in the server-rendered HTML, findable with the browser's find-in-page, or keeping its state across a collapse. Pass `keepContentMounted` there.
|
|
8
|
+
**Ticket:** CTAP-2217
|
|
9
|
+
|
|
10
|
+
## Dependencies
|
|
11
|
+
|
|
12
|
+
*None*
|
|
13
|
+
|
|
14
|
+
## Summary
|
|
15
|
+
|
|
16
|
+
The react-aria `Accordion` that replaced heroui's in `@clicktap/ui` 2.0 rendered every item's content,
|
|
17
|
+
expanded or not, and hid collapsed items with CSS only. Collapsed content mounted, ran its effects and
|
|
18
|
+
queries, and filled the DOM. One consumer's page, with a data-fetching panel per group and nested
|
|
19
|
+
accordions, sent 520 GraphQL requests and rendered about 72,000 hidden DOM nodes on load. heroui never
|
|
20
|
+
mounted a collapsed item unless `keepContentMounted` was set, and `AccordionProps` kept declaring that
|
|
21
|
+
prop, but the component ignored it.
|
|
22
|
+
|
|
23
|
+
The default is now heroui's: a collapsed item's content is not rendered. It mounts when the item expands,
|
|
24
|
+
stays mounted while the collapse transition runs, then unmounts. `keepContentMounted` works again.
|
|
25
|
+
|
|
26
|
+
## Changes
|
|
27
|
+
|
|
28
|
+
| | Before | After |
|
|
29
|
+
| --- | --- | --- |
|
|
30
|
+
| Collapsed item, default | Content mounted, hidden by CSS | Content not rendered |
|
|
31
|
+
| Expanding | Already mounted | Content mounts |
|
|
32
|
+
| Collapsing | Stays mounted | Unmounts once the height transition ends (or after 250 ms) |
|
|
33
|
+
| `keepContentMounted` on `Accordion` | Accepted, ignored | Every item's content always mounted, as before this fix |
|
|
34
|
+
| `keepContentMounted` on `AccordionItem` | Not a prop | Overrides the `Accordion`'s value for that item, in either direction |
|
|
35
|
+
|
|
36
|
+
The panel element itself (`DisclosurePanel`, the target of the trigger's `aria-controls`) is still always
|
|
37
|
+
rendered; only its children are conditional.
|
|
38
|
+
|
|
39
|
+
**Source**: `libs/frontend-modules/ui/src/components/Accordion/Accordion.tsx` (`AccordionPanel`)
|
|
40
|
+
|
|
41
|
+
## Migrate
|
|
42
|
+
|
|
43
|
+
Most accordions need nothing: menus, filters, cookie categories and checkout sections are interactive
|
|
44
|
+
content that nobody needs before it is opened. Pass `keepContentMounted` where one of these holds.
|
|
45
|
+
|
|
46
|
+
1. **The content must be in the initial HTML**, typically for search engines: FAQ answers, product
|
|
47
|
+
details, specifications.
|
|
48
|
+
|
|
49
|
+
```tsx
|
|
50
|
+
<Accordion keepContentMounted>
|
|
51
|
+
{faqs.map((faq) => (
|
|
52
|
+
<AccordionItem key={faq.id} title={faq.question}>
|
|
53
|
+
{faq.answer}
|
|
54
|
+
</AccordionItem>
|
|
55
|
+
))}
|
|
56
|
+
</Accordion>
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
The platform's reference storefront does this in `apps/frontend/components/FAQ/FAQ.tsx`.
|
|
60
|
+
|
|
61
|
+
2. **State inside the panel must survive a collapse**: a half-filled form, a payment widget that
|
|
62
|
+
initializes once, a nested accordion's open item. Set it on the whole accordion or on just that
|
|
63
|
+
item:
|
|
64
|
+
|
|
65
|
+
```tsx
|
|
66
|
+
<Accordion>
|
|
67
|
+
<AccordionItem key="card" title="Card" keepContentMounted>
|
|
68
|
+
<CardForm />
|
|
69
|
+
</AccordionItem>
|
|
70
|
+
<AccordionItem key="paypal" title="PayPal">
|
|
71
|
+
<PayPalButton />
|
|
72
|
+
</AccordionItem>
|
|
73
|
+
</Accordion>
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
An item can also opt out of a group-level `keepContentMounted` with `keepContentMounted={false}`.
|
|
77
|
+
|
|
78
|
+
3. **Code that reads collapsed content from the DOM** (a test that queries a collapsed item's text, a
|
|
79
|
+
script that measures it) must expand the item first, or the accordion must keep its content mounted.
|
|
80
|
+
|
|
81
|
+
Find your call sites:
|
|
82
|
+
|
|
83
|
+
```bash
|
|
84
|
+
grep -rn '<Accordion\b' apps/ libs/ --include=*.tsx
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
## Verify
|
|
88
|
+
|
|
89
|
+
- With the default, open a page with an accordion and search the page source (view-source, not the
|
|
90
|
+
inspector) for text from a collapsed item: it is absent. Expanding the item renders it.
|
|
91
|
+
- With `keepContentMounted`, the same text is present in the page source.
|
|
92
|
+
- On a page whose panels fetch data, the network panel shows no requests for collapsed items until they
|
|
93
|
+
are opened.
|
|
@@ -1,4 +1,14 @@
|
|
|
1
1
|
[
|
|
2
|
+
{
|
|
3
|
+
"path": "2026/10/ui-2026-10-06-accordion-mounts-collapsed-content-on-expand.md",
|
|
4
|
+
"module": "libs/frontend-modules/ui",
|
|
5
|
+
"package": "@clicktap/ui",
|
|
6
|
+
"date": "2026-10-06",
|
|
7
|
+
"title": "`Accordion` mounts a collapsed item's content only when it expands",
|
|
8
|
+
"classification": "BUGFIX",
|
|
9
|
+
"breaking": "No API change. ⚠️ Behavior change for any consumer that relies on collapsed content being in the server-rendered HTML, findable with the browser's find-in-page, or keeping its state across a collapse. Pass `keepContentMounted` there.",
|
|
10
|
+
"affects": "`components/Accordion` (`Accordion`, `AccordionItem`)"
|
|
11
|
+
},
|
|
2
12
|
{
|
|
3
13
|
"path": "2026/10/ui-2026-10-02-user-icon-drops-project-color-class.md",
|
|
4
14
|
"module": "libs/frontend-modules/ui",
|