Skip to content

Commit

Permalink
Fix EnterPasswordPage autofocus (#573)
Browse files Browse the repository at this point in the history
  • Loading branch information
mymindstorm authored Jan 14, 2021
1 parent f8d31af commit 6e00097
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 4 deletions.
1 change: 1 addition & 0 deletions src/components/Popup/EnterPasswordPage.vue
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
v-model="password"
@enter="applyPassphrase()"
:class="{ badInput: wrongPassword }"
:autofocus="true"
/>
<label class="warning" v-show="wrongPassword">{{
i18n.phrase_not_match
Expand Down
13 changes: 11 additions & 2 deletions src/components/common/TextInput.vue
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,23 @@
:value="value"
@input="$emit('input', $event.target.value)"
@keyup.enter="$emit('enter')"
autofocus
ref="textInput"
/>
</div>
</template>
<script lang="ts">
import Vue from "vue";
export default Vue.extend({
props: ["label", "value", "type"],
props: ["label", "value", "type", "autofocus"],
mounted() {
if (!this.$props.autofocus) {
return;
}
const textInput = this.$refs.textInput;
if (textInput instanceof HTMLInputElement) {
textInput.focus();
}
},
});
</script>
16 changes: 14 additions & 2 deletions src/test/components/Popup/EnterPasswordPage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import CommonComponents from "../../../components/common/index";
import EnterPasswordPage from "../../../components/Popup/EnterPasswordPage.vue";
import { loadI18nMessages } from "../../../store/i18n";

chai.should();
const should = chai.should();
chai.use(sinonChai);
mocha.setup("bdd");
const localVue = createLocalVue();
Expand Down Expand Up @@ -41,7 +41,7 @@ describe("EnterPasswordPage", () => {

beforeEach(() => {
// TODO: find a nicer var
storeOpts.modules.accounts.actions.applyPassphrase = sinon.fake();
storeOpts.modules.accounts.actions.applyPassphrase.resetHistory();
store = new Vuex.Store(storeOpts);
});

Expand Down Expand Up @@ -72,6 +72,18 @@ describe("EnterPasswordPage", () => {
);
});

it("should autofocus password input", () => {
const wrapper = mount(EnterPasswordPage, {
store,
localVue,
attachToDocument: true,
});

const passwordInput = wrapper.find("input");

passwordInput.element.should.eq(document.activeElement);
});

it("should not show incorrect password message", () => {
const wrapper = mount(EnterPasswordPage, { store, localVue });

Expand Down

0 comments on commit 6e00097

Please sign in to comment.