Add form support to `Password`

pull/6632/head
Mert Sincan 2024-10-22 09:47:22 +01:00
parent 6fded55811
commit f1a584fd2d
3 changed files with 16 additions and 35 deletions

View File

@ -1,12 +1,11 @@
<script> <script>
import BaseComponent from '@primevue/core/basecomponent'; import BaseInput from '@primevue/core/baseinput';
import PasswordStyle from 'primevue/password/style'; import PasswordStyle from 'primevue/password/style';
export default { export default {
name: 'BasePassword', name: 'BasePassword',
extends: BaseComponent, extends: BaseInput,
props: { props: {
modelValue: String,
promptLabel: { promptLabel: {
type: String, type: String,
default: null default: null
@ -59,14 +58,6 @@ export default {
type: String, type: String,
default: undefined default: undefined
}, },
variant: {
type: String,
default: null
},
invalid: {
type: Boolean,
default: false
},
disabled: { disabled: {
type: Boolean, type: Boolean,
default: false default: false
@ -79,10 +70,6 @@ export default {
type: Boolean, type: Boolean,
default: false default: false
}, },
fluid: {
type: Boolean,
default: null
},
inputId: { inputId: {
type: String, type: String,
default: null default: null

View File

@ -1,12 +1,13 @@
<template> <template>
<div :class="cx('root')" :style="sx('root')" v-bind="ptmi('root')"> <div :class="cx('root')" :style="sx('root')" v-bind="ptmi('root')">
<PInputText <InputText
ref="input" ref="input"
:id="inputId" :id="inputId"
:type="inputType" :type="inputType"
:class="[cx('pcInputText'), inputClass]" :class="[cx('pcInputText'), inputClass]"
:style="inputStyle" :style="inputStyle"
:value="modelValue" :value="d_value"
:name="$formName"
:aria-labelledby="ariaLabelledby" :aria-labelledby="ariaLabelledby"
:aria-label="ariaLabel" :aria-label="ariaLabel"
:aria-controls="(overlayProps && overlayProps.id) || overlayId || (panelProps && panelProps.id) || panelId || overlayUniqueId" :aria-controls="(overlayProps && overlayProps.id) || overlayId || (panelProps && panelProps.id) || panelId || overlayUniqueId"
@ -67,7 +68,6 @@
<script> <script>
import { absolutePosition, addStyle, getOuterWidth, isTouchDevice, relativePosition } from '@primeuix/utils/dom'; import { absolutePosition, addStyle, getOuterWidth, isTouchDevice, relativePosition } from '@primeuix/utils/dom';
import { isEmpty } from '@primeuix/utils/object';
import { ZIndex } from '@primeuix/utils/zindex'; import { ZIndex } from '@primeuix/utils/zindex';
import { ConnectedOverlayScrollHandler, UniqueComponentId } from '@primevue/core/utils'; import { ConnectedOverlayScrollHandler, UniqueComponentId } from '@primevue/core/utils';
import EyeIcon from '@primevue/icons/eye'; import EyeIcon from '@primevue/icons/eye';
@ -81,7 +81,7 @@ export default {
name: 'Password', name: 'Password',
extends: BasePassword, extends: BasePassword,
inheritAttrs: false, inheritAttrs: false,
emits: ['update:modelValue', 'change', 'focus', 'blur', 'invalid'], emits: ['change', 'focus', 'blur', 'invalid'],
inject: { inject: {
$pcFluid: { default: null } $pcFluid: { default: null }
}, },
@ -159,14 +159,14 @@ export default {
return level; return level;
}, },
onInput(event) { onInput(event) {
this.$emit('update:modelValue', event.target.value); this.updateValue(event.target.value, event);
this.$emit('change', event); this.$emit('change', event);
}, },
onFocus(event) { onFocus(event) {
this.focused = true; this.focused = true;
if (this.feedback) { if (this.feedback) {
this.setPasswordMeter(this.modelValue); this.setPasswordMeter(this.d_value);
this.overlayVisible = true; this.overlayVisible = true;
} }
@ -201,14 +201,14 @@ export default {
} }
}, },
setPasswordMeter() { setPasswordMeter() {
if (!this.modelValue) { if (!this.d_value) {
this.meter = null; this.meter = null;
this.infoText = this.promptText; this.infoText = this.promptText;
return; return;
} }
const { meter, label } = this.checkPasswordStrength(this.modelValue); const { meter, label } = this.checkPasswordStrength(this.d_value);
this.meter = meter; this.meter = meter;
this.infoText = label; this.infoText = label;
@ -307,9 +307,6 @@ export default {
inputType() { inputType() {
return this.unmasked ? 'text' : 'password'; return this.unmasked ? 'text' : 'password';
}, },
filled() {
return this.modelValue != null && this.modelValue.toString().length > 0;
},
weakText() { weakText() {
return this.weakLabel || this.$primevue.config.locale.weak; return this.weakLabel || this.$primevue.config.locale.weak;
}, },
@ -324,16 +321,13 @@ export default {
}, },
overlayUniqueId() { overlayUniqueId() {
return this.id + '_overlay'; return this.id + '_overlay';
},
hasFluid() {
return isEmpty(this.fluid) ? !!this.$pcFluid : this.fluid;
} }
}, },
components: { components: {
PInputText: InputText, InputText,
Portal: Portal, Portal,
EyeSlashIcon: EyeSlashIcon, EyeSlashIcon,
EyeIcon: EyeIcon EyeIcon
} }
}; };
</script> </script>

View File

@ -86,9 +86,9 @@ const classes = {
root: ({ instance }) => [ root: ({ instance }) => [
'p-password p-component p-inputwrapper', 'p-password p-component p-inputwrapper',
{ {
'p-inputwrapper-filled': instance.filled, 'p-inputwrapper-filled': instance.$filled,
'p-inputwrapper-focus': instance.focused, 'p-inputwrapper-focus': instance.focused,
'p-password-fluid': instance.hasFluid 'p-password-fluid': instance.$fluid
} }
], ],
pcInputText: 'p-password-input', pcInputText: 'p-password-input',