|
4 | 4 | <li |
5 | 5 | v-for="(option, index) in question.options" |
6 | 6 | v-on:click.prevent="toggleAnswer(option)" |
7 | | - v-bind:class="{'f-selected': option.selected, 'f-previous': isPreviousOption(option)}" |
| 7 | + v-on:mouseover="isIconScale ? onMouseover(index) : null" |
| 8 | + v-on:mouseleave="isIconScale ? onMouseleave : null" |
| 9 | + v-bind:class="{'f-selected': option.selected, ...iconScaleClasses(index)}" |
8 | 10 | v-bind:key="'m' + index" |
9 | 11 | v-bind:aria-label="getLabel(option.value)" |
10 | 12 | role="option" |
11 | 13 | > |
12 | 14 | <div v-if="!isIconScale" class="f-label-wrap"> |
13 | 15 | <span v-if="option.choiceLabel()" class="f-label">{{ option.choiceLabel() }}</span> |
14 | 16 | </div> |
15 | | - <div v-else-if="isIconScale" class="f-icon-wrap"> |
| 17 | + <div class="f-icon-wrap"> |
16 | 18 | <div class="f-icon"> |
17 | 19 | <svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24"> |
18 | 20 | <path d="M12 .587l3.668 7.568 8.332 1.151-6.064 5.828 1.48 8.279-7.416-3.967-7.417 3.967 1.481-8.279-6.064-5.828 8.332-1.151z" stroke-width=".5"/> |
|
23 | 25 | </li> |
24 | 26 | </ul> |
25 | 27 | <div v-if="!isIconScale && (question.labelLeft || question.labelRight)" class="f-label-scale-wrap"> |
26 | | - <span class="f-label-scale"> |
| 28 | + <span v-if="question.labelLeft" class="f-label-scale"> |
27 | 29 | <span class="f-label-scale-num">1 - </span> |
28 | 30 | {{ question.labelLeft }} |
29 | 31 | </span> |
30 | | - <span class="f-label-scale"> |
| 32 | + <span v-if="question.labelRight" class="f-label-scale"> |
31 | 33 | <span class="f-label-scale-num">{{ question.options.length }} - </span> |
32 | 34 | {{ question.labelRight }} |
33 | 35 | </span> |
|
44 | 46 |
|
45 | 47 | import BaseType from './BaseType.vue' |
46 | 48 | import { ChoiceOption, QuestionType } from '../../models/QuestionModel' |
| 49 | + import { IsMobile } from '../../mixins/IsMobile' |
47 | 50 |
|
48 | 51 | export default { |
49 | 52 | extends: BaseType, |
|
52 | 55 | data() { |
53 | 56 | return { |
54 | 57 | isIconScale: false, |
55 | | - activeIndex: null |
| 58 | + hoveredIndex: null, |
| 59 | + activeIndex: null, |
56 | 60 | } |
57 | 61 | }, |
58 | 62 |
|
| 63 | + mixins: [ |
| 64 | + IsMobile, |
| 65 | + ], |
| 66 | +
|
59 | 67 | beforeMount() { |
60 | 68 | const |
61 | 69 | size = this.question.maxSize ?? 5, |
|
96 | 104 | document.removeEventListener('keyup', this.onKeyListener) |
97 | 105 | }, |
98 | 106 |
|
| 107 | + onMouseover(index) { |
| 108 | + this.hoveredIndex = index |
| 109 | + }, |
| 110 | +
|
| 111 | + onMouseleave() { |
| 112 | + this.hoveredIndex = null |
| 113 | + }, |
| 114 | +
|
99 | 115 | /** |
100 | 116 | * Listens for keyboard events (1, 2, 3, ...) |
101 | 117 | */ |
|
121 | 137 | return this.language.ariaMultipleChoice.replace(':letter', this.getToggleKey(index)) |
122 | 138 | }, |
123 | 139 |
|
124 | | - isPreviousOption(option) { |
125 | | - return this.getPreviousOptions.includes(option) |
126 | | - }, |
127 | | -
|
128 | 140 | getToggleKey(num) { |
129 | 141 | return num |
130 | 142 | }, |
|
141 | 153 | this._toggleAnswer(option) |
142 | 154 | }, |
143 | 155 |
|
144 | | - _toggleAnswer(option) { |
| 156 | + async _toggleAnswer(option) { |
145 | 157 | const optionValue = option.choiceValue() |
146 | 158 |
|
147 | 159 | option.toggle() |
148 | | -
|
| 160 | + this.activeIndex = option.selected ? this.question.options.indexOf(option) : null |
| 161 | + |
149 | 162 | this.dataValue = option.selected ? optionValue : null |
150 | | - this.activeIndex = this.question.options.indexOf(option) |
151 | 163 | |
152 | 164 | if (this.isValid() && this.question.nextStepOnAnswer && !this.disabled) { |
153 | 165 | this.$emit('next') |
|
163 | 175 | this.dataValue.splice(index, 1) |
164 | 176 | } |
165 | 177 | }, |
| 178 | +
|
| 179 | + iconScaleClasses(index) { |
| 180 | + const classes = {} |
| 181 | +
|
| 182 | + if (this.isIconScale) { |
| 183 | + if (!this.isMobile) { |
| 184 | + classes['f-hovered'] = this.hoveredIndex ? index <= this.hoveredIndex : null |
| 185 | + } |
| 186 | +
|
| 187 | + classes['f-previous'] = this.activeIndex ? index < this.activeIndex : null |
| 188 | + } |
| 189 | +
|
| 190 | + return classes |
| 191 | + } |
166 | 192 | }, |
167 | 193 |
|
168 | 194 | computed: { |
|
172 | 198 | } |
173 | 199 |
|
174 | 200 | return false |
175 | | - }, |
176 | | -
|
177 | | - getPreviousOptions() { |
178 | | - return this.question.options.filter((o, index) => index < this.activeIndex) |
179 | 201 | } |
180 | 202 | } |
181 | 203 | } |
|
0 commit comments