Collapse: collapse item can be disabled (#15076)

pull/15050/head
hetech 2019-04-19 12:18:44 +08:00 committed by GitHub
parent 52959d0630
commit 3f0820d839
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 28 additions and 14 deletions

View File

@ -126,5 +126,6 @@ Besides using the `title` attribute, you can customize panel title with named sl
### Collapse Item Attributes ### Collapse Item Attributes
| Attribute | Description | Type | Accepted Values | Default | | Attribute | Description | Type | Accepted Values | Default |
|---------- |-------------- |---------- |-------------------------------- |-------- | |---------- |-------------- |---------- |-------------------------------- |-------- |
| name | unique identification of the panel | string/number | — | — | | name | unique identification of the panel | string/number | — | — |
| title | title of the panel | string | — | — | | title | title of the panel | string | — | — |
| disabled | disable the collapse item | boolean | — | — |

View File

@ -128,4 +128,5 @@ Además de usar el atributo `title`, se puede personalizar el título del panel
| Atributo | Descripción | Tipo | Valores aceptados | Por defecto | | Atributo | Descripción | Tipo | Valores aceptados | Por defecto |
| -------- | ----------------------------- | ------------- | ----------------- | ----------- | | -------- | ----------------------------- | ------------- | ----------------- | ----------- |
| name | identificador único del panel | string/number | — | — | | name | identificador único del panel | string/number | — | — |
| title | título del panel | string | — | — | | title | título del panel | string | — | — |
| disabled | disable the collapse item | boolean | — | — |

View File

@ -126,5 +126,6 @@ En plus de l'utilisation de l'attribut `title`, vous pouvez configurer les titre
### Attributs de Collapse-Item ### Attributs de Collapse-Item
| Attribut | Description | Type | Valeurs acceptées | Défaut | | Attribut | Description | Type | Valeurs acceptées | Défaut |
|---------- |-------------- |---------- |-------------------------------- |-------- | |---------- |-------------- |---------- |-------------------------------- |-------- |
| name | Identifiant unique du panneau. | string/number | — | — | | name | Identifiant unique du panneau. | string/number | — | — |
| title | Titre du panneau. | string | — | — | | title | Titre du panneau. | string | — | — |
| disabled | disable the collapse item | boolean | — | — |

View File

@ -126,5 +126,6 @@
### Collapse Item Attributes ### Collapse Item Attributes
| 参数 | 说明 | 类型 | 可选值 | 默认值 | | 参数 | 说明 | 类型 | 可选值 | 默认值 |
|---------- |-------------- |---------- |-------------------------------- |-------- | |---------- |-------------- |---------- |-------------------------------- |-------- |
| name | 唯一标志符 | string/number | — | — | | name | 唯一标志符 | string/number | — | — |
| title | 面板标题 | string | — | — | | title | 面板标题 | string | — | — |
| disabled | 是否禁用 | boolean | — | — |

View File

@ -1,5 +1,6 @@
<template> <template>
<div class="el-collapse-item" :class="{'is-active': isActive}"> <div class="el-collapse-item"
:class="{'is-active': isActive, 'is-disabled': disabled }">
<div <div
role="tab" role="tab"
:aria-expanded="isActive" :aria-expanded="isActive"
@ -11,7 +12,7 @@
@click="handleHeaderClick" @click="handleHeaderClick"
role="button" role="button"
:id="`el-collapse-head-${id}`" :id="`el-collapse-head-${id}`"
tabindex="0" :tabindex="disabled ? undefined : 0"
@keyup.space.enter.stop="handleEnterClick" @keyup.space.enter.stop="handleEnterClick"
:class="{ :class="{
'focusing': focusing, 'focusing': focusing,
@ -65,7 +66,8 @@
}, },
contentHeight: 0, contentHeight: 0,
focusing: false, focusing: false,
isClick: false isClick: false,
id: generateId()
}; };
}, },
@ -78,15 +80,13 @@
default() { default() {
return this._uid; return this._uid;
} }
} },
disabled: Boolean
}, },
computed: { computed: {
isActive() { isActive() {
return this.collapse.activeNames.indexOf(this.name) > -1; return this.collapse.activeNames.indexOf(this.name) > -1;
},
id() {
return generateId();
} }
}, },
@ -101,6 +101,7 @@
}, 50); }, 50);
}, },
handleHeaderClick() { handleHeaderClick() {
if (this.disabled) return;
this.dispatch('ElCollapse', 'item-click', this); this.dispatch('ElCollapse', 'item-click', this);
this.focusing = false; this.focusing = false;
this.isClick = true; this.isClick = true;

View File

@ -7,6 +7,12 @@
border-bottom: 1px solid $--collapse-border-color; border-bottom: 1px solid $--collapse-border-color;
} }
@include b(collapse-item) { @include b(collapse-item) {
@include when(disabled) {
.el-collapse-item__header {
color: $--font-color-disabled-base;
cursor: not-allowed;
}
}
@include e(header) { @include e(header) {
display: flex; display: flex;
align-items: center; align-items: center;

View File

@ -20,4 +20,7 @@ export declare class ElCollapseItem extends ElementUIComponent {
title: string title: string
$slots: CollapseItemSlots $slots: CollapseItemSlots
/** Disable the collapse item */
disabled: boolean
} }