Skip to content

Commit 80e9e60

Browse files
Refactor #8117 - For Password
1 parent 5ecb1aa commit 80e9e60

File tree

5 files changed

+41
-1
lines changed

5 files changed

+41
-1
lines changed

packages/primevue/src/password/BasePassword.vue

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,10 @@ export default {
5858
type: String,
5959
default: undefined
6060
},
61+
showClear: {
62+
type: Boolean,
63+
default: false
64+
},
6165
disabled: {
6266
type: Boolean,
6367
default: false

packages/primevue/src/password/Password.d.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,10 @@ export interface PasswordPassThroughOptions {
8383
* Used to pass attributes to the unmask icon's DOM element.
8484
*/
8585
unmaskIcon?: PasswordPassThroughOptionType;
86+
/**
87+
* Used to pass attributes to the clear icon's DOM element.
88+
*/
89+
clearIcon?: PasswordPassThroughOptionType;
8690
/**
8791
* Used to pass attributes to the overlay's DOM element.
8892
*/
@@ -231,6 +235,11 @@ export interface PasswordProps extends Omit<InputHTMLAttributes, 'size'> {
231235
* Icon to show displaying the password as plain text.
232236
*/
233237
unmaskIcon?: string | undefined;
238+
/**
239+
* When enabled, a clear icon is displayed to clear the value.
240+
* @defaultValue false
241+
*/
242+
showClear?: boolean | undefined;
234243
/**
235244
* Defines the size of the component.
236245
*/
@@ -408,6 +417,17 @@ export interface PasswordSlots {
408417
*/
409418
toggleCallback: () => void;
410419
}): VNode[];
420+
/**
421+
* Custom clear icon template.
422+
* @param {Object} scope - clear icon slot's params.
423+
*/
424+
clearicon(scope: {
425+
/**
426+
* Clear icon click function.
427+
* @param {Event} event - Browser event
428+
*/
429+
clearCallback: (event: Event) => void;
430+
}): VNode[];
411431
}
412432

413433
/**

packages/primevue/src/password/Password.vue

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@
3737
<slot v-if="toggleMask && !unmasked" :name="$slots.unmaskicon ? 'unmaskicon' : 'showicon'" :toggleCallback="onMaskToggle" :class="[cx('unmaskIcon')]" v-bind="ptm('unmaskIcon')">
3838
<component :is="unmaskIcon ? 'i' : 'EyeIcon'" :class="[cx('unmaskIcon'), unmaskIcon]" @click="onMaskToggle" v-bind="ptm('unmaskIcon')" />
3939
</slot>
40+
<slot v-if="isClearIconVisible" name="clearicon" :class="cx('clearIcon')" :clearCallback="onClearClick">
41+
<TimesIcon :class="[cx('clearIcon')]" @click="onClearClick" v-bind="ptm('clearIcon')" />
42+
</slot>
4043
<span class="p-hidden-accessible" aria-live="polite" v-bind="ptm('hiddenAccesible')" :data-p-hidden-accessible="true">
4144
{{ infoText }}
4245
</span>
@@ -77,6 +80,7 @@ import { ZIndex } from '@primeuix/utils/zindex';
7780
import { ConnectedOverlayScrollHandler } from '@primevue/core/utils';
7881
import EyeIcon from '@primevue/icons/eye';
7982
import EyeSlashIcon from '@primevue/icons/eyeslash';
83+
import TimesIcon from '@primevue/icons/times';
8084
import InputText from 'primevue/inputtext';
8185
import OverlayEventBus from 'primevue/overlayeventbus';
8286
import Portal from 'primevue/portal';
@@ -297,6 +301,9 @@ export default {
297301
onMaskToggle() {
298302
this.unmasked = !this.unmasked;
299303
},
304+
onClearClick(event) {
305+
this.writeValue(null, {});
306+
},
300307
onOverlayClick(event) {
301308
OverlayEventBus.emit('overlay-click', {
302309
originalEvent: event,
@@ -320,6 +327,9 @@ export default {
320327
promptText() {
321328
return this.promptLabel || this.$primevue.config.locale.passwordPrompt;
322329
},
330+
isClearIconVisible() {
331+
return this.showClear && this.$filled && !this.disabled;
332+
},
323333
overlayUniqueId() {
324334
return this.$id + '_overlay';
325335
},
@@ -343,7 +353,8 @@ export default {
343353
InputText,
344354
Portal,
345355
EyeSlashIcon,
346-
EyeIcon
356+
EyeIcon,
357+
TimesIcon
347358
}
348359
};
349360
</script>

packages/primevue/src/password/style/PasswordStyle.d.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@ export enum PasswordClasses {
2626
* Class name of the unmask icon element
2727
*/
2828
unmaskIcon = 'p-password-unmask-icon',
29+
/**
30+
* Class name of the clear icon element
31+
*/
32+
clearIcon = 'p-password-clear-icon',
2933
/**
3034
* Class name of the overlay element
3135
*/

packages/primevue/src/password/style/PasswordStyle.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ const classes = {
1717
pcInputText: 'p-password-input',
1818
maskIcon: 'p-password-toggle-mask-icon p-password-mask-icon',
1919
unmaskIcon: 'p-password-toggle-mask-icon p-password-unmask-icon',
20+
clearIcon: 'p-password-clear-icon',
2021
overlay: 'p-password-overlay p-component',
2122
content: 'p-password-content',
2223
meter: 'p-password-meter',

0 commit comments

Comments
 (0)