Blame view

node_modules/element-ui/packages/radio/src/radio-button.vue 2.67 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
114
  <template>
    <label
      class="el-radio-button"
      :class="[
        size ? 'el-radio-button--' + size : '',
        { 'is-active': value === label },
        { 'is-disabled': isDisabled },
        { 'is-focus': focus }
      ]"
      role="radio"
      :aria-checked="value === label"
      :aria-disabled="isDisabled"
      :tabindex="tabIndex"
      @keydown.space.stop.prevent="value = isDisabled ? value : label"
    >
      <input
        class="el-radio-button__orig-radio"
        :value="label"
        type="radio"
        v-model="value"
        :name="name"
        @change="handleChange"
        :disabled="isDisabled"
        tabindex="-1"
        @focus="focus = true"
        @blur="focus = false"
      >
      <span
        class="el-radio-button__inner"
        :style="value === label ? activeStyle : null"
        @keydown.stop>
        <slot></slot>
        <template v-if="!$slots.default">{{label}}</template>
      </span>
    </label>
  </template>
  <script>
    import Emitter from 'element-ui/src/mixins/emitter';
  
    export default {
      name: 'ElRadioButton',
  
      mixins: [Emitter],
  
      inject: {
        elForm: {
          default: ''
        },
        elFormItem: {
          default: ''
        }
      },
  
      props: {
        label: {},
        disabled: Boolean,
        name: String
      },
      data() {
        return {
          focus: false
        };
      },
      computed: {
        value: {
          get() {
            return this._radioGroup.value;
          },
          set(value) {
            this._radioGroup.$emit('input', value);
          }
        },
        _radioGroup() {
          let parent = this.$parent;
          while (parent) {
            if (parent.$options.componentName !== 'ElRadioGroup') {
              parent = parent.$parent;
            } else {
              return parent;
            }
          }
          return false;
        },
        activeStyle() {
          return {
            backgroundColor: this._radioGroup.fill || '',
            borderColor: this._radioGroup.fill || '',
            boxShadow: this._radioGroup.fill ? `-1px 0 0 0 ${this._radioGroup.fill}` : '',
            color: this._radioGroup.textColor || ''
          };
        },
        _elFormItemSize() {
          return (this.elFormItem || {}).elFormItemSize;
        },
        size() {
          return this._radioGroup.radioGroupSize || this._elFormItemSize || (this.$ELEMENT || {}).size;
        },
        isDisabled() {
          return this.disabled || this._radioGroup.disabled || (this.elForm || {}).disabled;
        },
        tabIndex() {
          return (this.isDisabled || (this._radioGroup && this.value !== this.label)) ? -1 : 0;
        }
      },
  
      methods: {
        handleChange() {
          this.$nextTick(() => {
            this.dispatch('ElRadioGroup', 'handleChange', this.value);
          });
        }
      }
    };
  </script>