Blame view

node_modules/element-ui/packages/collapse/src/collapse-item.vue 2.59 KB
2a09d1a4   liuqimichale   添加宜春 天水 宣化
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
  <template>
    <div class="el-collapse-item" :class="{'is-active': isActive}">
      <div
        role="tab"
        :aria-expanded="isActive"
        :aria-controls="`el-collapse-content-${id}`"
        :aria-describedby ="`el-collapse-content-${id}`"
      >
        <div
          class="el-collapse-item__header"
          @click="handleHeaderClick"
          role="button"
          :id="`el-collapse-head-${id}`"
          tabindex="0"
          @keyup.space.enter.stop="handleEnterClick"
          :class="{
            'focusing': focusing,
            'is-active': isActive
          }"
          @focus="handleFocus"
          @blur="focusing = false"
        >
          <slot name="title">{{title}}</slot>
          <i
            class="el-collapse-item__arrow el-icon-arrow-right"
            :class="{'is-active': isActive}">
          </i>
        </div>
      </div>
      <el-collapse-transition>
        <div
          class="el-collapse-item__wrap"
          v-show="isActive"
          role="tabpanel"
          :aria-hidden="!isActive"
          :aria-labelledby="`el-collapse-head-${id}`"
          :id="`el-collapse-content-${id}`"
        >
          <div class="el-collapse-item__content">
            <slot></slot>
          </div>
        </div>
      </el-collapse-transition>
    </div>
  </template>
  <script>
    import ElCollapseTransition from 'element-ui/src/transitions/collapse-transition';
    import Emitter from 'element-ui/src/mixins/emitter';
    import { generateId } from 'element-ui/src/utils/util';
  
    export default {
      name: 'ElCollapseItem',
  
      componentName: 'ElCollapseItem',
  
      mixins: [Emitter],
  
      components: { ElCollapseTransition },
  
      data() {
        return {
          contentWrapStyle: {
            height: 'auto',
            display: 'block'
          },
          contentHeight: 0,
          focusing: false,
          isClick: false
        };
      },
  
      inject: ['collapse'],
  
      props: {
        title: String,
        name: {
          type: [String, Number],
          default() {
            return this._uid;
          }
        }
      },
  
      computed: {
        isActive() {
          return this.collapse.activeNames.indexOf(this.name) > -1;
        },
        id() {
          return generateId();
        }
      },
  
      methods: {
        handleFocus() {
          setTimeout(() => {
            if (!this.isClick) {
              this.focusing = true;
            } else {
              this.isClick = false;
            }
          }, 50);
        },
        handleHeaderClick() {
          this.dispatch('ElCollapse', 'item-click', this);
          this.focusing = false;
          this.isClick = true;
        },
        handleEnterClick() {
          this.dispatch('ElCollapse', 'item-click', this);
        }
      }
    };
  </script>