Blame view

src/components/select/option.vue 2.26 KB
e355dd49   梁灏   add Select Component
1
  <template>
c9b86944   Sergio Crisostomo   Refactor Select!
2
      <li :class="classes" @click.stop="select"><slot>{{ showLabel }}</slot></li>
e355dd49   梁灏   add Select Component
3
4
  </template>
  <script>
4aec6a66   梁灏   support Select
5
      import Emitter from '../../mixins/emitter';
fed3e09d   梁灏   add AutoComplete ...
6
      import { findComponentUpward } from '../../utils/assist';
4aec6a66   梁灏   support Select
7
  
e355dd49   梁灏   add Select Component
8
9
10
      const prefixCls = 'ivu-select-item';
  
      export default {
4aec6a66   梁灏   support Select
11
12
13
          name: 'iOption',
          componentName: 'select-item',
          mixins: [ Emitter ],
e355dd49   梁灏   add Select Component
14
15
16
17
18
19
20
21
22
23
24
          props: {
              value: {
                  type: [String, Number],
                  required: true
              },
              label: {
                  type: [String, Number]
              },
              disabled: {
                  type: Boolean,
                  default: false
c9b86944   Sergio Crisostomo   Refactor Select!
25
26
27
28
29
30
31
32
              },
              selected: {
                  type: Boolean,
                  default: false
              },
              isFocused: {
                  type: Boolean,
                  default: false
e355dd49   梁灏   add Select Component
33
34
              }
          },
e355dd49   梁灏   add Select Component
35
36
          data () {
              return {
c9b86944   Sergio Crisostomo   Refactor Select!
37
                  searchLabel: '',  // the slot value (textContent)
fed3e09d   梁灏   add AutoComplete ...
38
                  autoComplete: false
b0893113   jingsam   :art: add eslint
39
              };
e355dd49   梁灏   add Select Component
40
41
42
43
44
45
46
          },
          computed: {
              classes () {
                  return [
                      `${prefixCls}`,
                      {
                          [`${prefixCls}-disabled`]: this.disabled,
fed3e09d   梁灏   add AutoComplete ...
47
                          [`${prefixCls}-selected`]: this.selected && !this.autoComplete,
c9b86944   Sergio Crisostomo   Refactor Select!
48
                          [`${prefixCls}-focus`]: this.isFocused
e355dd49   梁灏   add Select Component
49
                      }
b0893113   jingsam   :art: add eslint
50
                  ];
e355dd49   梁灏   add Select Component
51
52
              },
              showLabel () {
b0893113   jingsam   :art: add eslint
53
                  return (this.label) ? this.label : this.value;
c9b86944   Sergio Crisostomo   Refactor Select!
54
55
56
              },
              optionLabel(){
                  return (this.$el && this.$el.textContent) || this.label;
e355dd49   梁灏   add Select Component
57
58
59
60
              }
          },
          methods: {
              select () {
c9b86944   Sergio Crisostomo   Refactor Select!
61
                  if (this.disabled) return false;
e355dd49   梁灏   add Select Component
62
  
c9b86944   Sergio Crisostomo   Refactor Select!
63
64
65
66
67
68
69
70
                  this.dispatch('iSelect', 'on-select-selected', {
                      value: this.value,
                      label: this.optionLabel,
                  });
                  this.$emit('on-select-selected', {
                      value: this.value,
                      label: this.optionLabel,
                  });
e355dd49   梁灏   add Select Component
71
              },
e355dd49   梁灏   add Select Component
72
          },
4aec6a66   梁灏   support Select
73
          mounted () {
fed3e09d   梁灏   add AutoComplete ...
74
75
              const Select = findComponentUpward(this, 'iSelect');
              if (Select) this.autoComplete = Select.autoComplete;
ed91d9b0   梁灏   update Select
76
          },
b0893113   jingsam   :art: add eslint
77
78
      };
  </script>