Skip to content

Commit 6e00097

Browse files
authored
Fix EnterPasswordPage autofocus (#573)
1 parent f8d31af commit 6e00097

File tree

3 files changed

+26
-4
lines changed

3 files changed

+26
-4
lines changed

src/components/Popup/EnterPasswordPage.vue

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
v-model="password"
77
@enter="applyPassphrase()"
88
:class="{ badInput: wrongPassword }"
9+
:autofocus="true"
910
/>
1011
<label class="warning" v-show="wrongPassword">{{
1112
i18n.phrase_not_match

src/components/common/TextInput.vue

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,23 @@
77
:value="value"
88
@input="$emit('input', $event.target.value)"
99
@keyup.enter="$emit('enter')"
10-
autofocus
10+
ref="textInput"
1111
/>
1212
</div>
1313
</template>
1414
<script lang="ts">
1515
import Vue from "vue";
1616
1717
export default Vue.extend({
18-
props: ["label", "value", "type"],
18+
props: ["label", "value", "type", "autofocus"],
19+
mounted() {
20+
if (!this.$props.autofocus) {
21+
return;
22+
}
23+
const textInput = this.$refs.textInput;
24+
if (textInput instanceof HTMLInputElement) {
25+
textInput.focus();
26+
}
27+
},
1928
});
2029
</script>

src/test/components/Popup/EnterPasswordPage.ts

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import CommonComponents from "../../../components/common/index";
1010
import EnterPasswordPage from "../../../components/Popup/EnterPasswordPage.vue";
1111
import { loadI18nMessages } from "../../../store/i18n";
1212

13-
chai.should();
13+
const should = chai.should();
1414
chai.use(sinonChai);
1515
mocha.setup("bdd");
1616
const localVue = createLocalVue();
@@ -41,7 +41,7 @@ describe("EnterPasswordPage", () => {
4141

4242
beforeEach(() => {
4343
// TODO: find a nicer var
44-
storeOpts.modules.accounts.actions.applyPassphrase = sinon.fake();
44+
storeOpts.modules.accounts.actions.applyPassphrase.resetHistory();
4545
store = new Vuex.Store(storeOpts);
4646
});
4747

@@ -72,6 +72,18 @@ describe("EnterPasswordPage", () => {
7272
);
7373
});
7474

75+
it("should autofocus password input", () => {
76+
const wrapper = mount(EnterPasswordPage, {
77+
store,
78+
localVue,
79+
attachToDocument: true,
80+
});
81+
82+
const passwordInput = wrapper.find("input");
83+
84+
passwordInput.element.should.eq(document.activeElement);
85+
});
86+
7587
it("should not show incorrect password message", () => {
7688
const wrapper = mount(EnterPasswordPage, { store, localVue });
7789

0 commit comments

Comments
 (0)