Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(Nc*Field): add #icon slot for forward compatibility with v9, #default slot is deprecated #6399

Merged
merged 1 commit into from
Jan 20, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 7 additions & 8 deletions src/components/NcInputField/NcInputField.vue
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ For a list of all available props and attributes, please check the [HTMLInputEle
:class="{
'input-field--disabled': disabled,
'input-field--label-outside': labelOutside || !isValidLabel,
'input-field--leading-icon': hasLeadingIcon,
'input-field--leading-icon': !!$scopedSlots.icon || !!$scopedSlots.default || !!$slots.default,
'input-field--trailing-icon': showTrailingButton || hasTrailingIcon,
'input-field--pill': pill,
}">
Expand Down Expand Up @@ -51,9 +51,12 @@ For a list of all available props and attributes, please check the [HTMLInputEle
</label>

<!-- Leading icon -->
<div v-show="hasLeadingIcon" class="input-field__icon input-field__icon--leading">
<!-- Leading material design icon in the text field, set the size to 18 -->
<slot />
<div v-show="!!$scopedSlots.icon || !!$scopedSlots.default || !!$slots.default" class="input-field__icon input-field__icon--leading">
<!-- @slot Leading icon, set the size to 18 -->
<slot name="icon">
<!-- @slot Deprecated, removed in v9: use #icon slot instead. -->
<slot />
</slot>
</div>

<!-- trailing button -->
Expand Down Expand Up @@ -285,10 +288,6 @@ export default {
return 'input' + GenRandomId()
},

hasLeadingIcon() {
return this.$slots.default
},

hasTrailingIcon() {
return this.success
},
Expand Down
10 changes: 8 additions & 2 deletions src/components/NcPasswordField/NcPasswordField.vue
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,14 @@ export default {
v-on="$listeners"
@trailing-button-click="togglePasswordVisibility"
@input="handleInput">
<!-- Default slot for the leading icon -->
<slot />
<template v-if="!!$scopedSlots.icon || !!$slots.default || !!$scopedSlots.default" #icon>
<!-- @slot Leading icon -->
<slot name="icon">
<!-- @slot Deprecated, removed in v9: use #icon slot instead. -->
<slot />
</slot>
</template>

<template #trailing-button-icon>
<Eye v-if="isPasswordHidden" :size="18" />
<EyeOff v-else :size="18" />
Expand Down
17 changes: 13 additions & 4 deletions src/components/NcTextField/NcTextField.vue
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,19 @@ and `minlength`.
trailing-button-icon="close"
:show-trailing-button="text1 !== ''"
@trailing-button-click="clearText">
<Magnify :size="20" />
<template #icon>
<Magnify :size="20" />
</template>
</NcTextField>
<NcTextField v-model="text4"
label="Internal label"
placeholder="That can be used together with placeholder"
trailing-button-icon="close"
:show-trailing-button="text4 !== ''"
@trailing-button-click="clearText">
<Lock :size="20" />
<template #icon>
<Lock :size="20" />
</template>
</NcTextField>
<NcTextField v-model="text2"
label="With helper text"
Expand Down Expand Up @@ -124,8 +128,13 @@ export default {
<NcInputField v-bind="propsAndAttrsToForward"
ref="inputField"
v-on="$listeners">
<!-- Default slot for the leading icon -->
<slot />
<template v-if="!!$scopedSlots.icon || !!$slots.default || !!$scopedSlots.default" #icon>
<!-- @slot Leading icon -->
<slot name="icon">
<!-- @slot Deprecated, removed in v9: use #icon slot instead. -->
<slot />
</slot>
</template>

<!-- Trailing icon slot, except for search type input as the browser already adds a trailing close icon -->
<template v-if="type !== 'search'" #trailing-button-icon>
Expand Down
Loading