@@ -93,40 +93,17 @@ export default {
9393```
9494</docs >
9595
96- <template >
97- <NcInputField v-bind =" propsToForward"
98- ref =" inputField"
99- v-model =" modelValue"
100- :error =" error || isValid === false"
101- :helper-text =" helperText || internalHelpMessage"
102- :input-class =" [inputClass, { 'password-field__input--secure-text': isPasswordHidden && asText }]"
103- :minlength =" minlength ?? passwordPolicy?.minLength ?? 0"
104- :success =" success || isValid === true"
105- :trailing-button-label =" isPasswordHidden ? t('Show password') : t('Hide password')"
106- :type =" isPasswordHidden && !asText ? 'password' : 'text'"
107- @trailing-button-click =" isPasswordHidden = !isPasswordHidden" >
108- <template v-if =" !! $slots .icon " #icon >
109- <!-- @slot Leading icon -->
110- <slot name =" icon" />
111- </template >
112- <template #trailing-button-icon >
113- <Eye v-if =" isPasswordHidden" :size =" 18" />
114- <EyeOff v-else :size =" 18" />
115- </template >
116- </NcInputField >
117- </template >
118-
11996<script setup lang="ts">
12097import type { NcInputFieldProps } from ' ../NcInputField/NcInputField.vue'
12198import type { Writable } from ' ../../utils/VueTypes.ts'
12299
123- import debounce from ' debounce '
100+ import { mdiEye , mdiEyeOff } from ' @mdi/js '
124101import axios from ' @nextcloud/axios'
125102import { getCapabilities } from ' @nextcloud/capabilities'
126103import { generateOcsUrl } from ' @nextcloud/router'
104+ import debounce from ' debounce'
127105import { computed , ref , useTemplateRef , watch } from ' vue'
128- import Eye from ' vue-material-design-icons/Eye.vue'
129- import EyeOff from ' vue-material-design-icons/EyeOff.vue'
106+ import NcIconSvgWrapper from ' ../NcIconSvgWrapper/NcIconSvgWrapper.vue'
130107import NcInputField from ' ../NcInputField/NcInputField.vue'
131108import { t } from ' ../../l10n.js'
132109import logger from ' ../../utils/logger.ts'
@@ -162,9 +139,14 @@ const props = withDefaults(defineProps<Omit<NcInputFieldProps, 'trailingButtonLa
162139 showTrailingButton: true ,
163140})
164141
165- const modelValue = defineModel <string >(' modelValue ' , { default: ' ' })
142+ const modelValue = defineModel <string >({ default: ' ' })
166143watch (modelValue , debounce (checkPassword , 500 ))
167144
145+ /**
146+ * The obfuscating state of the password.
147+ */
148+ const obfuscated = defineModel <boolean >(' obfuscated' , { default: true })
149+
168150const emit = defineEmits <{
169151 valid: []
170152 invalid: []
@@ -224,7 +206,6 @@ const { password_policy: passwordPolicy } = getCapabilities() as { password_poli
224206// internal state
225207const inputField = useTemplateRef (' inputField' )
226208
227- const isPasswordHidden = ref (true )
228209const internalHelpMessage = ref (' ' )
229210const isValid = ref <boolean >()
230211
@@ -276,6 +257,13 @@ async function checkPassword() {
276257 }
277258}
278259
260+ /**
261+ * Toggle the obfuscation of the password
262+ */
263+ function toggleObfuscation() {
264+ obfuscated .value = ! obfuscated .value
265+ }
266+
279267/**
280268 * Focus the input element
281269 *
@@ -296,6 +284,28 @@ function select() {
296284}
297285 </script >
298286
287+ <template >
288+ <NcInputField v-bind =" propsToForward"
289+ ref =" inputField"
290+ v-model =" modelValue"
291+ :error =" error || isValid === false"
292+ :helper-text =" helperText || internalHelpMessage"
293+ :input-class =" [inputClass, { 'password-field__input--secure-text': obfuscated && asText }]"
294+ :minlength =" minlength ?? passwordPolicy?.minLength ?? 0"
295+ :success =" success || isValid === true"
296+ :trailing-button-label =" obfuscated ? t('Show password') : t('Hide password')"
297+ :type =" obfuscated && !asText ? 'password' : 'text'"
298+ @trailing-button-click =" toggleObfuscation" >
299+ <template v-if =" !! $slots .icon " #icon >
300+ <!-- @slot Leading icon -->
301+ <slot name =" icon" />
302+ </template >
303+ <template #trailing-button-icon >
304+ <NcIconSvgWrapper :path =" obfuscated ? mdiEye : mdiEyeOff" />
305+ </template >
306+ </NcInputField >
307+ </template >
308+
299309<style lang="scss" scoped>
300310:deep(.password-field__input--secure-text ) {
301311 // Emulate password field look
0 commit comments