@data-slot/collapsible 0.2.74 → 0.2.77
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.
package/README.md
CHANGED
|
@@ -46,6 +46,7 @@ import { createCollapsible } from "@data-slot/collapsible";
|
|
|
46
46
|
|
|
47
47
|
const collapsible = createCollapsible(element, {
|
|
48
48
|
defaultOpen: false,
|
|
49
|
+
hiddenUntilFound: false,
|
|
49
50
|
onOpenChange: (open) => console.log(open),
|
|
50
51
|
});
|
|
51
52
|
```
|
|
@@ -55,6 +56,7 @@ const collapsible = createCollapsible(element, {
|
|
|
55
56
|
| Option | Type | Default | Description |
|
|
56
57
|
|--------|------|---------|-------------|
|
|
57
58
|
| `defaultOpen` | `boolean` | `false` | Initial open state |
|
|
59
|
+
| `hiddenUntilFound` | `boolean` | `false` | Use `hidden="until-found"` when closed |
|
|
58
60
|
| `onOpenChange` | `(open: boolean) => void` | `undefined` | Callback when open state changes (not called on init) |
|
|
59
61
|
|
|
60
62
|
### Data Attributes
|
|
@@ -64,6 +66,7 @@ Options can also be set via data attributes on the root element. JS options take
|
|
|
64
66
|
| Attribute | Type | Default | Description |
|
|
65
67
|
|-----------|------|---------|-------------|
|
|
66
68
|
| `data-default-open` | boolean | `false` | Initial open state |
|
|
69
|
+
| `data-hidden-until-found` | boolean | `false` | Use `hidden="until-found"` when closed |
|
|
67
70
|
|
|
68
71
|
Boolean attributes: present or `"true"` = true, `"false"` = false, absent = default.
|
|
69
72
|
|
|
@@ -120,8 +123,22 @@ Use `data-state` attributes for CSS styling (available on both root and content)
|
|
|
120
123
|
[data-slot="collapsible-content"][data-state="open"] {
|
|
121
124
|
max-height: 500px;
|
|
122
125
|
}
|
|
126
|
+
|
|
127
|
+
/* Presence lifecycle markers */
|
|
128
|
+
[data-slot="collapsible-content"][data-starting-style] {
|
|
129
|
+
opacity: 0;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
[data-slot="collapsible-content"][data-ending-style] {
|
|
133
|
+
opacity: 0;
|
|
134
|
+
}
|
|
123
135
|
```
|
|
124
136
|
|
|
137
|
+
## Find-in-Page Support
|
|
138
|
+
|
|
139
|
+
Enable `hiddenUntilFound` (or `data-hidden-until-found`) to close panels with
|
|
140
|
+
`hidden="until-found"`. This allows browser find-in-page to reveal matching text.
|
|
141
|
+
|
|
125
142
|
With Tailwind:
|
|
126
143
|
|
|
127
144
|
```html
|
|
@@ -2,6 +2,11 @@
|
|
|
2
2
|
interface CollapsibleOptions {
|
|
3
3
|
/** Initial open state */
|
|
4
4
|
defaultOpen?: boolean;
|
|
5
|
+
/**
|
|
6
|
+
* Use hidden="until-found" when closed so browser find-in-page can reveal content.
|
|
7
|
+
* @default false
|
|
8
|
+
*/
|
|
9
|
+
hiddenUntilFound?: boolean;
|
|
5
10
|
/**
|
|
6
11
|
* Callback when open state changes.
|
|
7
12
|
* Note: Not called on initial render, only on subsequent state changes.
|
|
@@ -2,6 +2,11 @@
|
|
|
2
2
|
interface CollapsibleOptions {
|
|
3
3
|
/** Initial open state */
|
|
4
4
|
defaultOpen?: boolean;
|
|
5
|
+
/**
|
|
6
|
+
* Use hidden="until-found" when closed so browser find-in-page can reveal content.
|
|
7
|
+
* @default false
|
|
8
|
+
*/
|
|
9
|
+
hiddenUntilFound?: boolean;
|
|
5
10
|
/**
|
|
6
11
|
* Callback when open state changes.
|
|
7
12
|
* Note: Not called on initial render, only on subsequent state changes.
|
package/dist/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});let e=require(`@data-slot/core`);const t=new WeakSet;function n(n,r={}){let i=r.defaultOpen??(0,e.getDataBool)(n,`defaultOpen`)??!1,a=r.
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});let e=require(`@data-slot/core`);const t=new WeakSet;function n(n,r={}){let i=r.defaultOpen??(0,e.getDataBool)(n,`defaultOpen`)??!1,a=r.hiddenUntilFound??(0,e.getDataBool)(n,`hiddenUntilFound`)??!1,o=r.onOpenChange,s=(0,e.getPart)(n,`collapsible-trigger`),c=(0,e.getPart)(n,`collapsible-content`);if(!s||!c)throw Error(`Collapsible requires trigger and content slots`);let l=i,u=[],d=(0,e.ensureId)(c,`collapsible-content`),f=(0,e.ensureId)(s,`collapsible-trigger`);s.setAttribute(`aria-controls`,d),c.setAttribute(`role`,`region`),c.setAttribute(`aria-labelledby`,f);let p=e=>{n.setAttribute(`data-state`,e),c.setAttribute(`data-state`,e)},m=()=>{c.removeAttribute(`hidden`)},h=()=>{a?c.setAttribute(`hidden`,`until-found`):c.hidden=!0},g=(0,e.createPresenceLifecycle)({element:c,onExitComplete:()=>{h()}}),_=t=>{l!==t&&(l=t,(0,e.setAria)(s,`expanded`,l),p(l?`open`:`closed`),l?(m(),g.enter()):g.exit(),(0,e.emit)(n,`collapsible:change`,{open:l}),o?.(l))};return(0,e.setAria)(s,`expanded`,l),l?m():h(),p(l?`open`:`closed`),u.push((0,e.on)(s,`click`,()=>{s.hasAttribute(`disabled`)||s.getAttribute(`aria-disabled`)===`true`||_(!l)})),a&&u.push((0,e.on)(c,`beforematch`,()=>{l||_(!0)})),u.push((0,e.on)(n,`collapsible:set`,e=>{if(s.hasAttribute(`disabled`)||s.getAttribute(`aria-disabled`)===`true`)return;let t=e.detail,n;t?.open===void 0?t?.value!==void 0&&(n=t.value):n=t.open,typeof n==`boolean`&&_(n)})),{open:()=>_(!0),close:()=>_(!1),toggle:()=>_(!l),get isOpen(){return l},destroy:()=>{g.cleanup(),u.forEach(e=>e()),u.length=0,t.delete(n)}}}function r(r=document){let i=[];for(let a of(0,e.getRoots)(r,`collapsible`))t.has(a)||(t.add(a),i.push(n(a)));return i}exports.create=r,exports.createCollapsible=n;
|
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{createPresenceLifecycle as e,emit as t,ensureId as n,getDataBool as r,getPart as i,getRoots as a,on as o,setAria as s}from"@data-slot/core";const c=new WeakSet;function l(a,l={}){let u=l.defaultOpen??r(a,`defaultOpen`)??!1,d=l.hiddenUntilFound??r(a,`hiddenUntilFound`)??!1,f=l.onOpenChange,p=i(a,`collapsible-trigger`),m=i(a,`collapsible-content`);if(!p||!m)throw Error(`Collapsible requires trigger and content slots`);let h=u,g=[],_=n(m,`collapsible-content`),v=n(p,`collapsible-trigger`);p.setAttribute(`aria-controls`,_),m.setAttribute(`role`,`region`),m.setAttribute(`aria-labelledby`,v);let y=e=>{a.setAttribute(`data-state`,e),m.setAttribute(`data-state`,e)},b=()=>{m.removeAttribute(`hidden`)},x=()=>{d?m.setAttribute(`hidden`,`until-found`):m.hidden=!0},S=e({element:m,onExitComplete:()=>{x()}}),C=e=>{h!==e&&(h=e,s(p,`expanded`,h),y(h?`open`:`closed`),h?(b(),S.enter()):S.exit(),t(a,`collapsible:change`,{open:h}),f?.(h))};return s(p,`expanded`,h),h?b():x(),y(h?`open`:`closed`),g.push(o(p,`click`,()=>{p.hasAttribute(`disabled`)||p.getAttribute(`aria-disabled`)===`true`||C(!h)})),d&&g.push(o(m,`beforematch`,()=>{h||C(!0)})),g.push(o(a,`collapsible:set`,e=>{if(p.hasAttribute(`disabled`)||p.getAttribute(`aria-disabled`)===`true`)return;let t=e.detail,n;t?.open===void 0?t?.value!==void 0&&(n=t.value):n=t.open,typeof n==`boolean`&&C(n)})),{open:()=>C(!0),close:()=>C(!1),toggle:()=>C(!h),get isOpen(){return h},destroy:()=>{S.cleanup(),g.forEach(e=>e()),g.length=0,c.delete(a)}}}function u(e=document){let t=[];for(let n of a(e,`collapsible`))c.has(n)||(c.add(n),t.push(l(n)));return t}export{u as create,l as createCollapsible};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@data-slot/collapsible",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.77",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"sideEffects": false,
|
|
6
6
|
"main": "./dist/index.cjs",
|
|
@@ -38,6 +38,6 @@
|
|
|
38
38
|
],
|
|
39
39
|
"license": "MIT",
|
|
40
40
|
"dependencies": {
|
|
41
|
-
"@data-slot/core": "0.2.
|
|
41
|
+
"@data-slot/core": "0.2.77"
|
|
42
42
|
}
|
|
43
43
|
}
|