Skip to content

Commit 7cb35a1

Browse files
committed
AIQ-5472: Add iconIsClickable props
1 parent dddb940 commit 7cb35a1

File tree

4 files changed

+52
-12
lines changed

4 files changed

+52
-12
lines changed

docs/SelectMulti.stories.ts

+2
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ const Template = (args, { argTypes }) => ({
2323
:labelIsVisible="labelIsVisible"
2424
:placeholder="placeholder"
2525
:disabled="disabled"
26+
:iconIsClickable="iconIsClickable"
2627
:displayPillsBelowInput="displayPillsBelowInput"
2728
:noResultsMessage="noResultsMessage"
2829
:uniqueIdField="uniqueIdField"
@@ -37,6 +38,7 @@ Primary.args = {
3738
labelField: 'label',
3839
labelIsVisible: true,
3940
loading: false,
41+
iconIsClickable: true,
4042
placeholder: 'Select Options',
4143
disabled: false,
4244
displayPillsBelowInput: false,

specs/SelectMulti.spec.ts

+43-10
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,19 @@ import { mount, Wrapper } from '@vue/test-utils'
22

33
import SelectMulti from '../src/SelectMulti.vue'
44

5+
const options = [
6+
{ label: 'Item One', value: 'one' },
7+
{ label: 'Item Two', value: 'two' },
8+
{ label: 'Item Three', value: 'three' }
9+
]
10+
511
describe('SelectMulti', () => {
612
let wrapper: Wrapper<Vue>
713

814
describe('given simple options', () => {
915
beforeEach(() => {
1016
// TODO: Share sample data between spec files & Storybook stories
11-
const options = [
12-
{ label: 'Item One', value: 'one' },
13-
{ label: 'Item Two', value: 'two' },
14-
{ label: 'Item Three', value: 'three' }
15-
]
17+
1618

1719
wrapper = mount({
1820
data() {
@@ -65,11 +67,6 @@ describe('SelectMulti', () => {
6567
})
6668
describe('label functionality', () => {
6769
it('adds the aria-labelledby attribute to the listbox', () => {
68-
const options = [
69-
{ label: 'Item One', value: 'one' },
70-
{ label: 'Item Two', value: 'two' },
71-
{ label: 'Item Three', value: 'three' }
72-
]
7370
wrapper = mount({
7471
data() {
7572
return { selectedOptions: [], options }},
@@ -81,5 +78,41 @@ describe('SelectMulti', () => {
8178
expect(Object.keys(input.attributes())).toContain('aria-labelledby')
8279
})
8380
})
81+
82+
describe('iconIsClickable works', () => {
83+
it('when iconIsClickable false its not clickable and wrapper is a div', () => {
84+
85+
wrapper = mount({
86+
data() {
87+
return { selectedOptions: [], options }},
88+
template: '<div><SelectMulti :options="options" v-model="selectedOptions" label="Sample SelectMulti" /></div>',
89+
components: { SelectMulti }
90+
})
91+
92+
const selectMulti = wrapper.findComponent(SelectMulti)
93+
94+
const inputIconBlock = selectMulti.find('.combo-input-icon-block')
95+
96+
expect(inputIconBlock.element.tagName === 'DIV').toBeTruthy()
97+
expect(inputIconBlock.classes('not-clickable')).toBe(true)
98+
})
99+
100+
it('when iconIsClickable true its clickable and wrapper is a button', () => {
101+
102+
wrapper = mount({
103+
data() {
104+
return { selectedOptions: [], options }},
105+
template: '<div><SelectMulti :options="options" v-model="selectedOptions" :iconIsClickable="true" label="Sample SelectMulti" /></div>',
106+
components: { SelectMulti }
107+
})
108+
109+
const selectMulti = wrapper.findComponent(SelectMulti)
110+
111+
const inputIconBlock = selectMulti.find('.combo-input-icon-block')
112+
113+
expect(inputIconBlock.element.tagName === 'BUTTON').toBeTruthy()
114+
expect(inputIconBlock.classes('not-clickable')).toBe(false)
115+
})
116+
})
84117
})
85118
})

src/SelectMulti.vue

+6-2
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,10 @@
138138
type: String,
139139
required: false,
140140
default: 'value'
141+
},
142+
iconIsClickable: {
143+
type: Boolean,
144+
default: false
141145
}
142146
},
143147
data() {
@@ -425,7 +429,7 @@
425429
</div>
426430
</slot>
427431
</div>
428-
<div class="combo-input-icon-block" :class="{ 'not-clickable': !$slots['input-icon'] }">
432+
<component :is="iconIsClickable ? 'button' : 'div'" @click="iconIsClickable ? updateMenuState(iconIsClickable) : false" class="combo-input-icon-block" :class="{ 'not-clickable': !iconIsClickable }">
429433
<template v-if="!loading">
430434
<slot name="input-icon">
431435
<svg class="combo-plus-icon" viewBox="0 0 10 10" xmlns="http://www.w3.org/2000/svg" fill="currentColor">
@@ -440,7 +444,7 @@
440444
<path d="M10.6353 4.71384C11.3212 7.36481 9.80202 10.0897 7.24202 10.8L7.55253 12C10.7525 11.1121 12.6516 7.70601 11.7941 4.39231L10.6353 4.71384Z" fill="currentColor"/>
441445
</svg>
442446
</template>
443-
</div>
447+
</component>
444448
</div>
445449
</div>
446450
</template>

src/styles/mixins.scss

+1
Original file line numberDiff line numberDiff line change
@@ -353,6 +353,7 @@ $spacer: 1.875rem; // 30px
353353
top: 50%;
354354
transform: translate(0, -50%);
355355
right: math.div($spacer, 1.5);
356+
border: none;
356357

357358
&.not-clickable {
358359
pointer-events: none;

0 commit comments

Comments
 (0)