Skip to content

Commit 8cc0754

Browse files
author
ancadorneanu
committed
Display alternative text (if given) when an option is selected
1 parent 18daab5 commit 8cc0754

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

src/components/AdvancedSelect.vue

+1-1
Original file line numberDiff line numberDiff line change
@@ -350,7 +350,7 @@ export default {
350350
return null;
351351
},
352352
values() {
353-
return Object.values(this.selected).map((o) => (o.icon ? `<i class="fa ${o.icon}"></i> ${o.text}` : o.text));
353+
return Object.values(this.selected).map((o) => (o.icon ? `<i class="fa ${o.icon}"></i> ${o.altText || o.text}` : (o.altText || o.text)));
354354
},
355355
valuesText() {
356356
if (this.displayMax && this.displayMax < this.values.length) {

tests/unit/AdvancedSelect.spec.js

+13
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,19 @@ describe('AdvancedSelect.vue', () => {
152152
expect(wrapper.findAll('div.btn-group > ul > li > ul > li > a > i.fa').length).toBe(1);
153153
expect(wrapper.vm.values).toEqual(['1', '<i class="fa fa-check"></i> 2']);
154154
});
155+
it('items with alternative text', () => {
156+
const wrapper = shallowMount(Select, {
157+
props: {
158+
options: [
159+
{ text: '1', value: 1 },
160+
{ text: '2', value: 2, altText: '2 - two' },
161+
],
162+
multiple: true,
163+
modelValue: [1, 2],
164+
},
165+
});
166+
expect(wrapper.vm.values).toEqual(['1', '2 - two']);
167+
});
155168
});
156169
describe('actions', () => {
157170
it('Default value is set', async () => {

0 commit comments

Comments
 (0)