Skip to content

Commit 02aa5ce

Browse files
fix: 🐛 修复 Collapse 使用 toggleAall 方法时不会触发 before-expand 钩子的问题 (#727)
1 parent 4bf8d1e commit 02aa5ce

File tree

8 files changed

+305
-189
lines changed

8 files changed

+305
-189
lines changed

docs/component/collapse.md

Lines changed: 98 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -54,20 +54,13 @@ const value = ref<string[]>(['item1'])
5454

5555
```html
5656
<wd-collapse v-model="value">
57-
<wd-collapse-item
58-
v-for="(item, index) in itemList"
59-
:before-expend="beforeExpend"
60-
:key="index"
61-
:title="item.title"
62-
:name="item.name"
63-
>
57+
<wd-collapse-item v-for="(item, index) in itemList" :before-expend="beforeExpend" :key="index" :title="item.title" :name="item.name">
6458
{{ item.body }}
6559
</wd-collapse-item>
6660
</wd-collapse>
6761
```
6862

6963
```ts
70-
7164
import { useToast } from '@/uni_modules/wot-design-uni'
7265
const toast = useToast()
7366
const value = ref<string[]>(['item1'])
@@ -152,14 +145,60 @@ Collapse 查看更多的模式下,可以使用插槽定义自己想要的折
152145
</wd-collapse>
153146
```
154147

148+
## 嵌套使用
149+
150+
`collapse`可以嵌套使用,同时由于`collapse-item`的内容容器存在默认的`padding`,所以嵌套的`collapse`需要设置`custom-body-style`或者`custom-body-class`来覆盖默认样式。
151+
152+
***以下为示例,也可以自行调整样式。***
153+
154+
:::tip 注意
155+
`custom-body-style``custom-body-class``$LOWEST_VERSION$`及以上版本支持。
156+
:::
157+
158+
```html
159+
<view class="collapse">
160+
<wd-collapse v-model="collapseRoot">
161+
<wd-collapse-item custom-body-style="padding:0 0 0 14px" v-for="item in 5" :key="item" :title="`标签${item}`" :name="`${item}`">
162+
<wd-collapse v-model="collapseList[item - 1]">
163+
<wd-collapse-item
164+
v-for="(item, index) in itemList"
165+
:custom-class="index === 0 ? 'no-border' : ''"
166+
:key="index"
167+
:title="item.title"
168+
:name="item.name"
169+
>
170+
{{ item.body }}
171+
</wd-collapse-item>
172+
</wd-collapse>
173+
</wd-collapse-item>
174+
</wd-collapse>
175+
</view>
176+
```
177+
```css
178+
.collapse {
179+
:deep() {
180+
.no-border {
181+
&::after {
182+
display: none;
183+
}
184+
}
185+
}
186+
}
187+
```
188+
189+
```ts
190+
const collapseRoot = ref<string[]>(['0'])
191+
const collapseList = ref<Array<string[]>>([['item1'], ['item2'], ['item3'], ['item4'], ['item5']])
192+
```
193+
155194
## CollapseItem Attributes
156195

157196
| 参数 | 说明 | 类型 | 可选值 | 默认值 | 最低版本 |
158197
| ------------- | ----------------------------------------------------------- | -------- | ------ | ------ | -------- |
159198
| name | 折叠栏的标识符 | string | - | - | - |
160-
| title | 折叠栏的标题, 支持同名 slot 自定义内容 | string | - | '' | - |
199+
| title | 折叠栏的标题, 支持同名 slot 自定义内容 | string | - | '' | - |
161200
| disabled | 禁用折叠栏 | boolean | - | false | - |
162-
| before-expend | 打开前的回调函数,返回 false 可以阻止打开,支持返回 Promise | Function | - | false | - |
201+
| before-expend | 打开前的回调函数,返回 false 可以阻止打开,支持返回 Promise | Function | - | - | - |
163202

164203
### `before-expend` 执行时会传递以下回调参数:
165204

@@ -185,24 +224,62 @@ Collapse 查看更多的模式下,可以使用插槽定义自己想要的折
185224

186225
## Methods
187226

188-
| 方法名 | 说明 | 参数 | 最低版本 |
189-
| --- | --- | --- | --- |
190-
| toggleAll | 切换所有面板展开状态,传 `true` 为全部展开,`false` 为全部收起,不传参为全部切换 | _options?: boolean \| object_ | 0.2.6 |
227+
| 方法名 | 说明 | 参数 | 最低版本 |
228+
| --------- | -------------------------------------------------------------------------------- | ------------------------------------ | -------- |
229+
| toggleAll | 切换所有面板展开状态,传 `true` 为全部展开,`false` 为全部收起,不传参为全部切换 | `options?: CollapseToggleAllOptions` | 0.2.6 |
230+
231+
### CollapseToggleAllOptions 参数说明
232+
233+
| 参数名 | 说明 | 类型 | 默认值 |
234+
| ------------ | ----------------------------------- | ------- | ------ |
235+
| expanded | 是否展开,true 为展开,false 为收起 | boolean | - |
236+
| skipDisabled | 是否跳过禁用项 | boolean | false |
237+
238+
### toggleAll 方法示例
239+
240+
```html
241+
<wd-collapse ref="collapse">...</wd-collapse>
242+
```
243+
244+
```ts
245+
import { ref } from 'vue'
246+
import type { CollapseInstance } from '@/uni_modules/wot-design-uni/components/wd-collapse/types'
247+
248+
const collapseRef = ref<CollapseInstance>()
249+
250+
// 全部切换
251+
collapseRef.value?.toggleAll()
252+
// 全部展开
253+
collapseRef.value?.toggleAll(true)
254+
// 全部收起
255+
collapseRef.value?.toggleAll(false)
256+
257+
// 全部全部切换,并跳过禁用项
258+
collapseRef.value?.toggleAll({
259+
skipDisabled: true
260+
})
261+
// 全部选中,并跳过禁用项
262+
collapseRef.value?.toggleAll({
263+
expanded: true,
264+
skipDisabled: true
265+
})
266+
```
191267

192268
## Collapse Slot
193269

194-
| name | 说明 | 最低版本 |
195-
| ---- | ---------------------------------------------------- | -------- |
196-
| title |标题,便于开发者自定义标题(非 viewmore 使用) | 1.2.27 |
197-
| more | 查看更多,便于开发者自定义查看更多类型的展开收起样式 | - |
270+
| name | 说明 | 最低版本 |
271+
| ----- | ---------------------------------------------------- | -------- |
272+
| title | 标题,便于开发者自定义标题(非 viewmore 使用) | 1.2.27 |
273+
| more | 查看更多,便于开发者自定义查看更多类型的展开收起样式 | - |
198274

199275
## CollapseItem 外部样式类
200276

201-
| 类名 | 说明 | 最低版本 |
202-
| ------------ | ----------------------- | -------- |
203-
| custom-class | collapseItem 根节点样式 | - |
277+
| 类名 | 说明 | 最低版本 |
278+
| ----------------- | ------------------------------ | ---------------- |
279+
| custom-class | collapseItem 根节点样式 | - |
280+
| custom-body-style | 自定义折叠面板内容容器的样式 | $LOWEST_VERSION$ |
281+
| custom-body-class | 自定义折叠面板内容容器的样式类 | $LOWEST_VERSION$ |
204282

205-
**注意:组件内插槽样式不生效,因此使用插槽时需注意添加外部样式类**
206283

207284
## Collapse 外部样式类
208285

0 commit comments

Comments
 (0)