Skip to content

Commit 73b06c9

Browse files
authored
Merge pull request #18 from elev8studio/filter-reset-behaviour
Filter reset behaviour
2 parents b69bc1e + 383517f commit 73b06c9

File tree

4 files changed

+39
-14
lines changed

4 files changed

+39
-14
lines changed

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
"moment": "^2.22.2"
1717
},
1818
"dependencies": {
19-
"font-awesome": "^4.7.0",
19+
"@vue-hero-icons/solid": "^1.7.2",
2020
"vue": "^2.5.0"
2121
}
2222
}

resources/js/components/DateRangeFilter.vue

+28-7
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,11 @@
3232

3333
<button
3434
v-show="isValidCurrentValue"
35-
class="reset-button btn btn-sm fa fa-times"
35+
class="reset-button btn btn-sm focus:outline-none flex justify-center items-center"
3636
@click="resetFilter"
37-
></button>
37+
>
38+
<XIcon class="reset-icon"/>
39+
</button>
3840
</div>
3941
</div>
4042
</div>
@@ -66,15 +68,34 @@
6668
};
6769
},
6870
71+
created () {
72+
/*
73+
* Clear the displayed value when clicking 'Reset Filters'
74+
* to reset all applied filters. Without this, the filter is
75+
* removed, but the input value remains, which is confusing.
76+
*/
77+
this.$store.subscribeAction((action, state) => {
78+
if (action.type === `${this.resourceName}/resetFilterState`) {
79+
this.resetFilter();
80+
}
81+
});
82+
},
83+
6984
methods: {
7085
handleChange: function (value) {
71-
if (Array.isArray(value) && value.length === 2) {
72-
value = value.map((value) => moment(value).format('YYYY-MM-DD'));
73-
}
86+
/*
87+
* Remove repetition and provide empty value when clear button is pressed.
88+
* This tells Nova that the filter is no longer enabled, changing the filter
89+
* icon colour from blue to regular colour. Without this fix, you can press
90+
* the clear button, but the filter icon still looks as if a filter is applied.
91+
*/
92+
value = Array.isArray(value) && value.length === 2
93+
? value.map((value) => moment(value).format('YYYY-MM-DD'))
94+
: [];
7495
7596
this.$store.commit(`${this.resourceName}/updateFilterState`, {
7697
filterClass: this.filterKey,
77-
value: Array.isArray(value) && value.length === 2 ? value : [],
98+
value: value,
7899
});
79100
80101
this.$emit('change');
@@ -94,7 +115,7 @@
94115
},
95116
96117
isValidCurrentValue: function () {
97-
return Array.isArray(this.filter.currentValue) && this.filter.currentValue.length === 2
118+
return Array.isArray(this.filter.currentValue) && this.filter.currentValue.length === 2;
98119
},
99120
100121
resetFilter: function () {

resources/js/components/DateRangePicker.vue

+4-4
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
type="text"
44
ref="dateRangePicker"
55
:disabled="disabled"
6-
:class="{ '!cursor-not-allowed': disabled }"
76
:placeholder="placeholder"
87
:value="value"
98
/>
@@ -136,7 +135,8 @@
136135
</script>
137136

138137
<style scoped>
139-
.\!cursor-not-allowed {
140-
cursor: not-allowed !important;
141-
}
138+
/* 'cursor: not-allowed' removed because the result is misleading -
139+
* when hovering the input field, the not-allowed cursor suggests
140+
* the field is not clickable, but you can still click it.
141+
*/
142142
</style>

resources/sass/filter.scss

+6-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
@import "~font-awesome/scss/font-awesome";
2-
31
.date-range-filter .input-wrapper {
42
$reset-button-width: 2rem !default;
53

@@ -18,6 +16,12 @@
1816
transition: opacity 0.4s;
1917
}
2018

19+
.reset-icon {
20+
width: 18px;
21+
height: 18px;
22+
color: #9d9d9d;
23+
}
24+
2125
&:hover .reset-button {
2226
opacity: 1;
2327
}

0 commit comments

Comments
 (0)