Skip to content

Commit

Permalink
move password field to composition api
Browse files Browse the repository at this point in the history
  • Loading branch information
Haberkamp committed Sep 3, 2024
1 parent 0f66c09 commit 2a2133f
Showing 1 changed file with 13 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
: $tc('mt-password-field.titleShowPassword')
"
class="mt-field__toggle-password-visibility"
@click="onTogglePasswordVisibility(disabled)"
@click="() => (showPassword = !showPassword)"
>
<mt-icon v-if="showPassword" name="solid-eye-slash" size="18" />

Expand All @@ -71,7 +71,7 @@
</mt-base-field>
</template>
<script lang="ts">
import { defineComponent } from "vue";
import { computed, defineComponent, ref } from "vue";
import MtIcon from "../../icons-media/mt-icon/mt-icon.vue";
import MtTextField from "../mt-text-field/mt-text-field.vue";
Expand Down Expand Up @@ -121,34 +121,19 @@ export default defineComponent({
},
},
data() {
return {
showPassword: false,
};
},
setup(props) {
const showPassword = ref(false);
computed: {
typeFieldClass(): string {
return this.passwordToggleAble
? "mt-field--password"
: "mt-field--password mt-field--password--untoggable";
},
const passwordPlaceholder = computed(() =>
showPassword.value || !props.placeholderIsPassword
? props.placeholder
: "*".repeat(props.placeholder.length ? props.placeholder.length : 6),
);
passwordPlaceholder(): string {
return this.showPassword || !this.placeholderIsPassword
? this.placeholder
: "*".repeat(this.placeholder.length ? this.placeholder.length : 6);
},
},
methods: {
onTogglePasswordVisibility(disabled: boolean) {
if (disabled) {
return;
}
this.showPassword = !this.showPassword;
},
return {
showPassword,
passwordPlaceholder,
};
},
});
</script>
Expand Down

0 comments on commit 2a2133f

Please sign in to comment.