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

Custom icons for checkbox component #3428

Closed
wants to merge 3 commits into from
Closed
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/checkbox.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,12 @@ const CheckboxProps = [
default: 'null',
description: 'Index of the element in tabbing order.'
},
{
name: 'icon',
type: 'string',
default: 'pi pi-check',
description: 'Icon to display in the checkbox.'
},
{
name: 'trueValue',
type: 'any',
Expand Down
4 changes: 4 additions & 0 deletions components/checkbox/Checkbox.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ export interface CheckboxProps {
* Index of the element in tabbing order.
*/
tabindex?: number | undefined;
/**
* Icon to display in the checkbox.
*/
icon?: string | undefined;
/**
* Value in checked state.
*/
Expand Down
6 changes: 6 additions & 0 deletions components/checkbox/Checkbox.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,10 @@ describe('Checkbox.vue', () => {
expect(wrapper.find('.p-checkbox-box.p-highlight').exists()).toBe(true);
expect(wrapper.find('.p-checkbox-icon.pi.pi-check').exists()).toBe(true);
});

it('should have custom icon when provided', async () => {
await wrapper.setProps({ icon: 'pi pi-discord', modelValue: true });

expect(wrapper.find('.p-checkbox-icon').classes()).toContain('pi-discord');
});
});
6 changes: 5 additions & 1 deletion components/checkbox/Checkbox.vue
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
/>
</div>
<div ref="box" :class="['p-checkbox-box', { 'p-highlight': checked, 'p-disabled': disabled, 'p-focus': focused }]">
<span :class="['p-checkbox-icon', { 'pi pi-check': checked }]"></span>
<span :class="['p-checkbox-icon', { [icon]: checked }]"></span>
</div>
</div>
</template>
Expand Down Expand Up @@ -65,6 +65,10 @@ export default {
type: Number,
default: null
},
icon: {
type: String,
default: 'pi pi-check'
},
inputId: {
type: String,
default: null
Expand Down
6 changes: 6 additions & 0 deletions pages/checkbox/CheckboxDoc.vue
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,12 @@ export default {
<td>null</td>
<td>Index of the element in tabbing order.</td>
</tr>
<tr>
<td>icon</td>
<td>string</td>
<td>pi pi-check</td>
<td>Icon to display in the checkbox.</td>
</tr>
<tr>
<td>inputId</td>
<td>string</td>
Expand Down