Skip to content

Commit 0240804

Browse files
committed
- remove redundant v-if condition, - add styling to previous options on hover, - add conditional rendering to label text
1 parent 6e4df19 commit 0240804

File tree

3 files changed

+40
-18
lines changed

3 files changed

+40
-18
lines changed

examples/questionnaire/Example.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@
106106
required: true,
107107
maxSize: 8,
108108
labelLeft: 'Awful',
109-
labelRight: 'Excellent'
109+
110110
}),
111111
new QuestionModel({
112112
id: 'first_name',

src/assets/css/common.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -876,7 +876,7 @@ header.vff-header svg.f-logo {
876876
background-color: unset;
877877
}
878878

879-
.vff .field-iconrate ul.f-radios li:hover .f-icon-wrap svg {
879+
.vff .field-iconrate ul.f-radios li.f-hovered .f-icon-wrap svg {
880880
fill: var(--vff-tertiary-text-color);
881881
}
882882

src/components/QuestionTypes/OpinionScaleType.vue

Lines changed: 38 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,17 @@
44
<li
55
v-for="(option, index) in question.options"
66
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)}"
810
v-bind:key="'m' + index"
911
v-bind:aria-label="getLabel(option.value)"
1012
role="option"
1113
>
1214
<div v-if="!isIconScale" class="f-label-wrap">
1315
<span v-if="option.choiceLabel()" class="f-label">{{ option.choiceLabel() }}</span>
1416
</div>
15-
<div v-else-if="isIconScale" class="f-icon-wrap">
17+
<div class="f-icon-wrap">
1618
<div class="f-icon">
1719
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24">
1820
<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,11 +25,11 @@
2325
</li>
2426
</ul>
2527
<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">
2729
<span class="f-label-scale-num">1 - </span>
2830
{{ question.labelLeft }}
2931
</span>
30-
<span class="f-label-scale">
32+
<span v-if="question.labelRight" class="f-label-scale">
3133
<span class="f-label-scale-num">{{ question.options.length }} - </span>
3234
{{ question.labelRight }}
3335
</span>
@@ -44,6 +46,7 @@
4446
4547
import BaseType from './BaseType.vue'
4648
import { ChoiceOption, QuestionType } from '../../models/QuestionModel'
49+
import { IsMobile } from '../../mixins/IsMobile'
4750
4851
export default {
4952
extends: BaseType,
@@ -52,10 +55,15 @@
5255
data() {
5356
return {
5457
isIconScale: false,
55-
activeIndex: null
58+
hoveredIndex: null,
59+
activeIndex: null,
5660
}
5761
},
5862
63+
mixins: [
64+
IsMobile,
65+
],
66+
5967
beforeMount() {
6068
const
6169
size = this.question.maxSize ?? 5,
@@ -96,6 +104,14 @@
96104
document.removeEventListener('keyup', this.onKeyListener)
97105
},
98106
107+
onMouseover(index) {
108+
this.hoveredIndex = index
109+
},
110+
111+
onMouseleave() {
112+
this.hoveredIndex = null
113+
},
114+
99115
/**
100116
* Listens for keyboard events (1, 2, 3, ...)
101117
*/
@@ -121,10 +137,6 @@
121137
return this.language.ariaMultipleChoice.replace(':letter', this.getToggleKey(index))
122138
},
123139
124-
isPreviousOption(option) {
125-
return this.getPreviousOptions.includes(option)
126-
},
127-
128140
getToggleKey(num) {
129141
return num
130142
},
@@ -141,13 +153,13 @@
141153
this._toggleAnswer(option)
142154
},
143155
144-
_toggleAnswer(option) {
156+
async _toggleAnswer(option) {
145157
const optionValue = option.choiceValue()
146158
147159
option.toggle()
148-
160+
this.activeIndex = option.selected ? this.question.options.indexOf(option) : null
161+
149162
this.dataValue = option.selected ? optionValue : null
150-
this.activeIndex = this.question.options.indexOf(option)
151163
152164
if (this.isValid() && this.question.nextStepOnAnswer && !this.disabled) {
153165
this.$emit('next')
@@ -163,6 +175,20 @@
163175
this.dataValue.splice(index, 1)
164176
}
165177
},
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+
}
166192
},
167193
168194
computed: {
@@ -172,10 +198,6 @@
172198
}
173199
174200
return false
175-
},
176-
177-
getPreviousOptions() {
178-
return this.question.options.filter((o, index) => index < this.activeIndex)
179201
}
180202
}
181203
}

0 commit comments

Comments
 (0)