Refactor #3832 Refactor #3833 - For Chips

pull/3841/head
Tuğçe Küçükoğlu 2023-04-04 15:39:59 +03:00
parent dbfbc31e8a
commit ad64a8aeab
3 changed files with 16 additions and 3 deletions

View File

@ -106,6 +106,10 @@ const ChipsSlots = [
{ {
name: 'chips', name: 'chips',
description: 'Custom content for the chips' description: 'Custom content for the chips'
},
{
name: 'removetokenicon',
description: 'Custom remove token icon template.'
} }
]; ];

View File

@ -76,7 +76,6 @@ export interface ChipsProps {
inputProps?: InputHTMLAttributes | undefined; inputProps?: InputHTMLAttributes | undefined;
/** /**
* Icon to display in chip remove action. * Icon to display in chip remove action.
* @defaultValue pi pi-times-circle
*/ */
removeTokenIcon?: string | undefined; removeTokenIcon?: string | undefined;
/** /**
@ -110,6 +109,10 @@ export interface ChipsSlots {
*/ */
value: any; value: any;
}): VNode[]; }): VNode[];
/**
* Custom remove token icon template.
*/
removetokenicon(): VNode[];
} }
/** /**
* Defines valid emits in Chips component. * Defines valid emits in Chips component.

View File

@ -28,7 +28,9 @@
<slot name="chip" :value="val"> <slot name="chip" :value="val">
<span class="p-chips-token-label">{{ val }}</span> <span class="p-chips-token-label">{{ val }}</span>
</slot> </slot>
<span :class="['p-chips-token-icon', removeTokenIcon]" @click="removeItem($event, i)" aria-hidden="true"></span> <slot name="removetokenicon">
<component :is="removeTokenIcon ? 'span' : 'TimesCircleIcon'" :class="['p-chips-token-icon', removeTokenIcon]" @click="removeItem($event, i)" aria-hidden="true" />
</slot>
</li> </li>
<li class="p-chips-input-token" role="option"> <li class="p-chips-input-token" role="option">
<input <input
@ -52,6 +54,7 @@
</template> </template>
<script> <script>
import TimesCircleIcon from 'primevue/icon/timescircle';
import { UniqueComponentId } from 'primevue/utils'; import { UniqueComponentId } from 'primevue/utils';
export default { export default {
@ -104,7 +107,7 @@ export default {
}, },
removeTokenIcon: { removeTokenIcon: {
type: String, type: String,
default: 'pi pi-times-circle' default: undefined
}, },
'aria-labelledby': { 'aria-labelledby': {
type: String, type: String,
@ -309,6 +312,9 @@ export default {
focusedOptionId() { focusedOptionId() {
return this.focusedIndex !== null ? `${this.id}_chips_item_${this.focusedIndex}` : null; return this.focusedIndex !== null ? `${this.id}_chips_item_${this.focusedIndex}` : null;
} }
},
components: {
TimesCircleIcon: TimesCircleIcon
} }
}; };
</script> </script>