Blame view

src/components/date-picker/base/confirm.vue 2.39 KB
b9041a0d   梁灏   DatePicker add co...
1
  <template>
75cb2998   Sergio Crisostomo   Add keyboard navi...
2
3
4
5
      <div :class="[prefixCls + '-confirm']" @keydown.tab.capture="handleTab">
          <i-button :class="timeClasses" size="small" type="text" :disabled="timeDisabled" v-if="showTime" @click="handleToggleTime">
              {{labels.time}}
          </i-button>
851dbcb3   梁灏   update component'...
6
          <i-button size="small" @click.native="handleClear" @keydown.enter.native="handleClear">
75cb2998   Sergio Crisostomo   Add keyboard navi...
7
8
9
10
11
              {{labels.clear}}
          </i-button>
          <i-button size="small" type="primary" @click.native="handleSuccess" @keydown.enter.native="handleSuccess">
              {{labels.ok}}
          </i-button>
b9041a0d   梁灏   DatePicker add co...
12
13
14
15
      </div>
  </template>
  <script>
      import iButton from '../../button/button.vue';
4ab11811   梁灏   some component su...
16
      import Locale from '../../../mixins/locale';
75cb2998   Sergio Crisostomo   Add keyboard navi...
17
      import Emitter from '../../../mixins/emitter';
b9041a0d   梁灏   DatePicker add co...
18
19
20
21
  
      const prefixCls = 'ivu-picker';
  
      export default {
75cb2998   Sergio Crisostomo   Add keyboard navi...
22
23
          mixins: [Locale, Emitter],
          components: {iButton},
5cc9b892   梁灏   update DateTimePi...
24
25
          props: {
              showTime: false,
2dc27713   梁灏   update DateTimePi...
26
27
              isTime: false,
              timeDisabled: false
5cc9b892   梁灏   update DateTimePi...
28
          },
75cb2998   Sergio Crisostomo   Add keyboard navi...
29
          data() {
b9041a0d   梁灏   DatePicker add co...
30
31
              return {
                  prefixCls: prefixCls
b0893113   jingsam   :art: add eslint
32
              };
b9041a0d   梁灏   DatePicker add co...
33
          },
2dc27713   梁灏   update DateTimePi...
34
35
          computed: {
              timeClasses () {
75cb2998   Sergio Crisostomo   Add keyboard navi...
36
37
38
39
40
41
42
43
44
                  return  `${prefixCls}-confirm-time`;
              },
              labels(){
                  const labels = ['time', 'clear', 'ok'];
                  const values = [(this.isTime ? 'selectDate' : 'selectTime'), 'clear', 'ok'];
                  return labels.reduce((obj, key, i) => {
                      obj[key] = this.t('i.datepicker.' + values[i]);
                      return obj;
                  }, {});
2dc27713   梁灏   update DateTimePi...
45
46
              }
          },
b9041a0d   梁灏   DatePicker add co...
47
48
49
50
51
52
          methods: {
              handleClear () {
                  this.$emit('on-pick-clear');
              },
              handleSuccess () {
                  this.$emit('on-pick-success');
5cc9b892   梁灏   update DateTimePi...
53
54
              },
              handleToggleTime () {
2dc27713   梁灏   update DateTimePi...
55
                  if (this.timeDisabled) return;
5cc9b892   梁灏   update DateTimePi...
56
                  this.$emit('on-pick-toggle-time');
75cb2998   Sergio Crisostomo   Add keyboard navi...
57
58
59
60
61
62
63
64
65
66
67
                  this.dispatch('CalendarPicker', 'focus-input');
              },
              handleTab(e) {
                  const tabbables = [...this.$el.children];
                  const expectedFocus = tabbables[e.shiftKey ? 'shift' : 'pop']();
  
                  if (document.activeElement === expectedFocus) {
                      e.preventDefault();
                      e.stopPropagation();
                      this.dispatch('CalendarPicker', 'focus-input');
                  }
b9041a0d   梁灏   DatePicker add co...
68
69
              }
          }
b0893113   jingsam   :art: add eslint
70
71
      };
  </script>