Browse Source

Merge pull request #732 from Leopoldthecoder/master

MessageBox: autofocus confirm button
SkyAo 8 years ago
parent
commit
8d37478a4b
1 changed files with 6 additions and 1 deletions
  1. 6 1
      packages/message-box/src/main.vue

+ 6 - 1
packages/message-box/src/main.vue

@@ -16,7 +16,7 @@
         </div>
         <div class="el-message-box__btns">
           <el-button :class="[ cancelButtonClasses ]" v-show="showCancelButton" @click.native="handleAction('cancel')">{{ cancelButtonText }}</el-button>
-          <el-button autofocus :class="[ confirmButtonClasses ]" v-show="showConfirmButton" @click.native="handleAction('confirm')">{{ confirmButtonText }}</el-button>
+          <el-button ref="confirm" :class="[ confirmButtonClasses ]" v-show="showConfirmButton" @click.native="handleAction('confirm')">{{ confirmButtonText }}</el-button>
         </div>
       </div>
     </transition>
@@ -146,6 +146,11 @@
       },
 
       value(val) {
+        if (this.$type === 'alert' || this.$type === 'confirm') {
+          this.$nextTick(() => {
+            this.$refs.confirm.$el.focus();
+          });
+        }
         if (this.$type !== 'prompt') return;
         if (val) {
           setTimeout(() => {