diff --git a/src/collapse-item/CollapseItem.tsx b/src/collapse-item/CollapseItem.tsx index fa0ed7b1d..5dbc71831 100644 --- a/src/collapse-item/CollapseItem.tsx +++ b/src/collapse-item/CollapseItem.tsx @@ -2,7 +2,7 @@ import { ref, watch, computed, nextTick, defineComponent } from 'vue'; // Utils import { cellProps } from '../cell/Cell'; -import { createNamespace } from '../utils'; +import { createNamespace, pick } from '../utils'; import { COLLAPSE_KEY, CollapseProvide } from '../collapse/Collapse'; // Composables @@ -22,6 +22,7 @@ export default defineComponent({ ...cellProps, name: [Number, String], disabled: Boolean, + readonly: Boolean, isLink: { type: Boolean, default: true, @@ -94,13 +95,24 @@ export default defineComponent({ }; const onClickTitle = () => { - if (!props.disabled) { + if (!props.disabled && !props.readonly) { toggle(); } }; const renderTitle = () => { - const { border, disabled } = props; + const { border, disabled, readonly } = props; + const attrs = pick( + props, + Object.keys(cellProps) as Array + ); + + if (readonly) { + attrs.isLink = false; + } + if (disabled || readonly) { + attrs.clickable = false; + } return ( ); }; diff --git a/src/collapse-item/index.less b/src/collapse-item/index.less index 1600d9219..bb530a8d4 100644 --- a/src/collapse-item/index.less +++ b/src/collapse-item/index.less @@ -44,10 +44,6 @@ & .van-cell__right-icon { color: @collapse-item-title-disabled-color; } - - &:active { - background-color: @white; - } } } diff --git a/src/collapse/README.md b/src/collapse/README.md index b1dc400a7..188576a88 100644 --- a/src/collapse/README.md +++ b/src/collapse/README.md @@ -132,6 +132,7 @@ export default { | label | Description below the title | _string_ | - | | border | Whether to show inner border | _boolean_ | `true` | | disabled | Whether to disabled collapse | _boolean_ | `false` | +| readonly `v3.0.12` | Whether to be readonly | _boolean_ | `false` | | is-link | Whether to show link icon | _boolean_ | `true` | | title-class | Title className | _string_ | - | | value-class | Value className | _string_ | - | diff --git a/src/collapse/README.zh-CN.md b/src/collapse/README.zh-CN.md index 0d4b6dcdc..10c1936e0 100644 --- a/src/collapse/README.zh-CN.md +++ b/src/collapse/README.zh-CN.md @@ -135,6 +135,7 @@ export default { | border | 是否显示内边框 | _boolean_ | `true` | | is-link | 是否展示标题栏右侧箭头并开启点击反馈 | _boolean_ | `true` | | disabled | 是否禁用面板 | _boolean_ | `false` | +| readonly `v3.0.12` | 是否为只读状态,只读状态下无法操作面板 | _boolean_ | `false` | | title-class | 左侧标题额外类名 | _string_ | - | | value-class | 右侧内容额外类名 | _string_ | - | | label-class | 描述信息额外类名 | _string_ | - | diff --git a/src/collapse/test/__snapshots__/demo.spec.ts.snap b/src/collapse/test/__snapshots__/demo.spec.ts.snap index 3e04e0444..7693a1511 100644 --- a/src/collapse/test/__snapshots__/demo.spec.ts.snap +++ b/src/collapse/test/__snapshots__/demo.spec.ts.snap @@ -8,7 +8,6 @@ exports[`should render demo and match snapshot 1`] = ` role="button" tabindex="0" aria-expanded="true" - disabled="false" >
@@ -29,7 +28,6 @@ exports[`should render demo and match snapshot 1`] = ` role="button" tabindex="0" aria-expanded="false" - disabled="false" >
@@ -45,7 +43,6 @@ exports[`should render demo and match snapshot 1`] = ` role="button" tabindex="0" aria-expanded="false" - disabled="false" >
@@ -65,7 +62,6 @@ exports[`should render demo and match snapshot 1`] = ` role="button" tabindex="0" aria-expanded="true" - disabled="false" >
@@ -86,7 +82,6 @@ exports[`should render demo and match snapshot 1`] = ` role="button" tabindex="0" aria-expanded="false" - disabled="false" >
@@ -102,7 +97,6 @@ exports[`should render demo and match snapshot 1`] = ` role="button" tabindex="0" aria-expanded="false" - disabled="false" >
@@ -122,7 +116,6 @@ exports[`should render demo and match snapshot 1`] = ` role="button" tabindex="0" aria-expanded="false" - disabled="false" >
@@ -134,11 +127,9 @@ exports[`should render demo and match snapshot 1`] = `
-
-