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

Add custom icons support for the Chips component #3053

Merged
merged 1 commit into from
Oct 28, 2022
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
6 changes: 6 additions & 0 deletions api-generator/components/chips.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,12 @@ const ChipsProps = [
type: 'object',
default: 'null',
description: 'Uses to pass all properties of the HTMLInputElement to the focusable input element inside the component.'
},
{
name: 'removeTokenIcon',
type: 'string',
default: 'pi pi-times-circle',
description: 'Icon to display in chip remove action.'
}
];

Expand Down
5 changes: 5 additions & 0 deletions src/components/chips/Chips.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,11 @@ export interface ChipsProps {
* Uses to pass all properties of the HTMLInputElement to the focusable input element inside the component.
*/
inputProps?: InputHTMLAttributes | undefined;
/**
* Icon to display in chip remove action.
* Default value is 'pi pi-times-circle'.
*/
removeTokenIcon?: string | undefined;
/**
* When present, it specifies that the element should be disabled.
*/
Expand Down
11 changes: 11 additions & 0 deletions src/components/chips/Chips.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,15 @@ describe('Chips.vue', () => {
expect(wrapper.find('.p-chips-token-label').exists()).toBe(true);
expect(wrapper.find('.p-chips-token-label').text()).toBe('PrimeVue');
});

it('should have correct custom chip removal icon', async () => {
await wrapper.setProps({
modelValue: ['foo', 'bar'],
removeTokenIcon: 'pi pi-discord'
});

const icon = wrapper.find('.p-chips-token-icon');

expect(icon.classes()).toContain('pi-discord');
});
});
6 changes: 5 additions & 1 deletion src/components/chips/Chips.vue
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
<slot name="chip" :value="val">
<span class="p-chips-token-label">{{ val }}</span>
</slot>
<span class="p-chips-token-icon pi pi-times-circle" @click="removeItem($event, i)" aria-hidden="true"></span>
<span :class="['p-chips-token-icon', removeTokenIcon]" @click="removeItem($event, i)" aria-hidden="true"></span>
</li>
<li class="p-chips-input-token" role="option">
<input
Expand Down Expand Up @@ -102,6 +102,10 @@ export default {
type: null,
default: null
},
removeTokenIcon: {
type: String,
default: 'pi pi-times-circle'
},
'aria-labelledby': {
type: String,
default: null
Expand Down
6 changes: 6 additions & 0 deletions src/views/chips/ChipsDoc.vue
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,12 @@ import Chips from 'primevue/chips';
<td>null</td>
<td>Uses to pass all properties of the HTMLInputElement to the focusable input element inside the component.</td>
</tr>
<tr>
<td>removeTokenIcon</td>
<td>string</td>
<td>pi pi-times-circle</td>
<td>Icon to display in chip remove action.</td>
</tr>
</tbody>
</table>
</div>
Expand Down