selectic 3.0.2 → 3.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/selectic.common.js +25 -13
- package/dist/selectic.esm.js +24 -12
- package/doc/params.md +5 -2
- package/package.json +6 -5
- package/src/Filter.tsx +18 -6
- package/src/Store.tsx +17 -1
- package/src/index.tsx +4 -3
- package/test/Store/Store_creation.spec.js +50 -0
- package/test/helper.js +1 -0
- package/types/Store.d.ts +4 -1
- package/types/index.d.ts +3 -3
package/dist/selectic.common.js
CHANGED
|
@@ -107,6 +107,7 @@ class SelecticStore {
|
|
|
107
107
|
disabled: false,
|
|
108
108
|
placeholder: '',
|
|
109
109
|
hideFilter: false,
|
|
110
|
+
keepFilterOpen: false,
|
|
110
111
|
allowRevert: undefined,
|
|
111
112
|
allowClearSelection: false,
|
|
112
113
|
autoSelect: true,
|
|
@@ -264,6 +265,10 @@ class SelecticStore {
|
|
|
264
265
|
if (stateParam.hideFilter === 'auto') {
|
|
265
266
|
delete stateParam.hideFilter;
|
|
266
267
|
}
|
|
268
|
+
else if (stateParam.hideFilter === 'open') {
|
|
269
|
+
this.state.keepFilterOpen = true;
|
|
270
|
+
delete stateParam.hideFilter;
|
|
271
|
+
}
|
|
267
272
|
/* Update state */
|
|
268
273
|
assignObject(this.state, stateParam);
|
|
269
274
|
/* XXX: should be done in 2 lines, in order to set the multiple state
|
|
@@ -1468,6 +1473,10 @@ let FilterPanel = class FilterPanel extends vtyx.Vue {
|
|
|
1468
1473
|
this.store.commit('selectionIsExcluded', !this.selectionIsExcluded);
|
|
1469
1474
|
}
|
|
1470
1475
|
togglePanel() {
|
|
1476
|
+
if (this.store.state.keepFilterOpen === true) {
|
|
1477
|
+
this.closed = false;
|
|
1478
|
+
return;
|
|
1479
|
+
}
|
|
1471
1480
|
this.closed = !this.closed;
|
|
1472
1481
|
}
|
|
1473
1482
|
getFocus() {
|
|
@@ -1484,7 +1493,8 @@ let FilterPanel = class FilterPanel extends vtyx.Vue {
|
|
|
1484
1493
|
/* }}} */
|
|
1485
1494
|
/* {{{ Life cycle */
|
|
1486
1495
|
mounted() {
|
|
1487
|
-
|
|
1496
|
+
const state = this.store.state;
|
|
1497
|
+
this.closed = !state.keepFilterOpen && !state.searchText;
|
|
1488
1498
|
document.addEventListener('keypress', this.onKeyPressed);
|
|
1489
1499
|
this.getFocus();
|
|
1490
1500
|
}
|
|
@@ -1493,24 +1503,27 @@ let FilterPanel = class FilterPanel extends vtyx.Vue {
|
|
|
1493
1503
|
}
|
|
1494
1504
|
/* }}} */
|
|
1495
1505
|
render() {
|
|
1506
|
+
const store = this.store;
|
|
1507
|
+
const state = store.state;
|
|
1508
|
+
const labels = store.data.labels;
|
|
1496
1509
|
return (vtyx.h("div", { class: "filter-panel" },
|
|
1497
1510
|
vtyx.h("div", { class: {
|
|
1498
1511
|
panelclosed: this.closed,
|
|
1499
1512
|
panelopened: !this.closed,
|
|
1500
1513
|
} },
|
|
1501
1514
|
vtyx.h("div", { class: "filter-panel__input form-group has-feedback" },
|
|
1502
|
-
vtyx.h("input", { type: "text", class: "form-control filter-input", placeholder: this.searchPlaceholder, value:
|
|
1515
|
+
vtyx.h("input", { type: "text", class: "form-control filter-input", placeholder: this.searchPlaceholder, value: state.searchText, on: {
|
|
1503
1516
|
'input.stop.prevent': this.onInput,
|
|
1504
1517
|
}, ref: "filterInput" }),
|
|
1505
1518
|
vtyx.h("span", { class: "fa fa-search selectic-search-scope\n form-control-feedback" })),
|
|
1506
|
-
|
|
1519
|
+
state.multiple && (vtyx.h("div", { class: "toggle-selectic" },
|
|
1507
1520
|
vtyx.h("label", { class: ['control-label', {
|
|
1508
1521
|
'selectic__label-disabled': this.disableSelectAll,
|
|
1509
1522
|
}] },
|
|
1510
|
-
vtyx.h("input", { type: "checkbox", checked:
|
|
1523
|
+
vtyx.h("input", { type: "checkbox", checked: state.status.areAllSelected, disabled: this.disableSelectAll, on: {
|
|
1511
1524
|
change: this.onSelectAll,
|
|
1512
1525
|
} }),
|
|
1513
|
-
|
|
1526
|
+
labels.selectAll))),
|
|
1514
1527
|
this.enableRevert && (vtyx.h("div", { class: ['toggle-selectic', {
|
|
1515
1528
|
'selectic__label-disabled': this.disableRevert,
|
|
1516
1529
|
}] },
|
|
@@ -1518,8 +1531,8 @@ let FilterPanel = class FilterPanel extends vtyx.Vue {
|
|
|
1518
1531
|
vtyx.h("input", { type: "checkbox", checked: this.selectionIsExcluded, disabled: this.disableRevert, on: {
|
|
1519
1532
|
change: this.onExclude,
|
|
1520
1533
|
} }),
|
|
1521
|
-
|
|
1522
|
-
vtyx.h("div", { class: "curtain-handler", on: {
|
|
1534
|
+
labels.excludeResult)))),
|
|
1535
|
+
!state.keepFilterOpen && (vtyx.h("div", { class: "curtain-handler", on: {
|
|
1523
1536
|
'click.prevent.stop': this.togglePanel,
|
|
1524
1537
|
} },
|
|
1525
1538
|
vtyx.h("span", { class: "fa fa-search" }),
|
|
@@ -1527,7 +1540,7 @@ let FilterPanel = class FilterPanel extends vtyx.Vue {
|
|
|
1527
1540
|
'fa': true,
|
|
1528
1541
|
'fa-caret-down': this.closed,
|
|
1529
1542
|
'fa-caret-up': !this.closed,
|
|
1530
|
-
} }))));
|
|
1543
|
+
} })))));
|
|
1531
1544
|
}
|
|
1532
1545
|
};
|
|
1533
1546
|
__decorate$3([
|
|
@@ -2370,7 +2383,7 @@ let Selectic = class Selectic extends vtyx.Vue {
|
|
|
2370
2383
|
/* }}} */
|
|
2371
2384
|
/* {{{ Life cycle */
|
|
2372
2385
|
created() {
|
|
2373
|
-
var _a, _b;
|
|
2386
|
+
var _a, _b, _c;
|
|
2374
2387
|
this._elementsListeners = [];
|
|
2375
2388
|
this.store = new SelecticStore({
|
|
2376
2389
|
options: this.options,
|
|
@@ -2383,8 +2396,7 @@ let Selectic = class Selectic extends vtyx.Vue {
|
|
|
2383
2396
|
params: {
|
|
2384
2397
|
multiple: ((_a = this.multiple) !== null && _a !== void 0 ? _a : false) !== false,
|
|
2385
2398
|
pageSize: this.params.pageSize || 100,
|
|
2386
|
-
hideFilter: this.params.hideFilter !==
|
|
2387
|
-
? this.params.hideFilter : 'auto',
|
|
2399
|
+
hideFilter: (_b = this.params.hideFilter) !== null && _b !== void 0 ? _b : 'auto',
|
|
2388
2400
|
allowRevert: this.params.allowRevert,
|
|
2389
2401
|
allowClearSelection: this.params.allowClearSelection || false,
|
|
2390
2402
|
autoSelect: this.params.autoSelect === undefined
|
|
@@ -2399,7 +2411,7 @@ let Selectic = class Selectic extends vtyx.Vue {
|
|
|
2399
2411
|
formatSelection: this.params.formatSelection,
|
|
2400
2412
|
listPosition: this.params.listPosition || 'auto',
|
|
2401
2413
|
optionBehavior: this.params.optionBehavior,
|
|
2402
|
-
isOpen: ((
|
|
2414
|
+
isOpen: ((_c = this.open) !== null && _c !== void 0 ? _c : false) !== false,
|
|
2403
2415
|
},
|
|
2404
2416
|
fetchCallback: this.params.fetchCallback,
|
|
2405
2417
|
getItemsCallback: this.params.getItemsCallback,
|
|
@@ -2551,4 +2563,4 @@ Selectic = __decorate([
|
|
|
2551
2563
|
var Selectic$1 = Selectic;
|
|
2552
2564
|
|
|
2553
2565
|
exports.changeTexts = changeTexts;
|
|
2554
|
-
exports[
|
|
2566
|
+
exports["default"] = Selectic$1;
|
package/dist/selectic.esm.js
CHANGED
|
@@ -103,6 +103,7 @@ class SelecticStore {
|
|
|
103
103
|
disabled: false,
|
|
104
104
|
placeholder: '',
|
|
105
105
|
hideFilter: false,
|
|
106
|
+
keepFilterOpen: false,
|
|
106
107
|
allowRevert: undefined,
|
|
107
108
|
allowClearSelection: false,
|
|
108
109
|
autoSelect: true,
|
|
@@ -260,6 +261,10 @@ class SelecticStore {
|
|
|
260
261
|
if (stateParam.hideFilter === 'auto') {
|
|
261
262
|
delete stateParam.hideFilter;
|
|
262
263
|
}
|
|
264
|
+
else if (stateParam.hideFilter === 'open') {
|
|
265
|
+
this.state.keepFilterOpen = true;
|
|
266
|
+
delete stateParam.hideFilter;
|
|
267
|
+
}
|
|
263
268
|
/* Update state */
|
|
264
269
|
assignObject(this.state, stateParam);
|
|
265
270
|
/* XXX: should be done in 2 lines, in order to set the multiple state
|
|
@@ -1464,6 +1469,10 @@ let FilterPanel = class FilterPanel extends Vue {
|
|
|
1464
1469
|
this.store.commit('selectionIsExcluded', !this.selectionIsExcluded);
|
|
1465
1470
|
}
|
|
1466
1471
|
togglePanel() {
|
|
1472
|
+
if (this.store.state.keepFilterOpen === true) {
|
|
1473
|
+
this.closed = false;
|
|
1474
|
+
return;
|
|
1475
|
+
}
|
|
1467
1476
|
this.closed = !this.closed;
|
|
1468
1477
|
}
|
|
1469
1478
|
getFocus() {
|
|
@@ -1480,7 +1489,8 @@ let FilterPanel = class FilterPanel extends Vue {
|
|
|
1480
1489
|
/* }}} */
|
|
1481
1490
|
/* {{{ Life cycle */
|
|
1482
1491
|
mounted() {
|
|
1483
|
-
|
|
1492
|
+
const state = this.store.state;
|
|
1493
|
+
this.closed = !state.keepFilterOpen && !state.searchText;
|
|
1484
1494
|
document.addEventListener('keypress', this.onKeyPressed);
|
|
1485
1495
|
this.getFocus();
|
|
1486
1496
|
}
|
|
@@ -1489,24 +1499,27 @@ let FilterPanel = class FilterPanel extends Vue {
|
|
|
1489
1499
|
}
|
|
1490
1500
|
/* }}} */
|
|
1491
1501
|
render() {
|
|
1502
|
+
const store = this.store;
|
|
1503
|
+
const state = store.state;
|
|
1504
|
+
const labels = store.data.labels;
|
|
1492
1505
|
return (h("div", { class: "filter-panel" },
|
|
1493
1506
|
h("div", { class: {
|
|
1494
1507
|
panelclosed: this.closed,
|
|
1495
1508
|
panelopened: !this.closed,
|
|
1496
1509
|
} },
|
|
1497
1510
|
h("div", { class: "filter-panel__input form-group has-feedback" },
|
|
1498
|
-
h("input", { type: "text", class: "form-control filter-input", placeholder: this.searchPlaceholder, value:
|
|
1511
|
+
h("input", { type: "text", class: "form-control filter-input", placeholder: this.searchPlaceholder, value: state.searchText, on: {
|
|
1499
1512
|
'input.stop.prevent': this.onInput,
|
|
1500
1513
|
}, ref: "filterInput" }),
|
|
1501
1514
|
h("span", { class: "fa fa-search selectic-search-scope\n form-control-feedback" })),
|
|
1502
|
-
|
|
1515
|
+
state.multiple && (h("div", { class: "toggle-selectic" },
|
|
1503
1516
|
h("label", { class: ['control-label', {
|
|
1504
1517
|
'selectic__label-disabled': this.disableSelectAll,
|
|
1505
1518
|
}] },
|
|
1506
|
-
h("input", { type: "checkbox", checked:
|
|
1519
|
+
h("input", { type: "checkbox", checked: state.status.areAllSelected, disabled: this.disableSelectAll, on: {
|
|
1507
1520
|
change: this.onSelectAll,
|
|
1508
1521
|
} }),
|
|
1509
|
-
|
|
1522
|
+
labels.selectAll))),
|
|
1510
1523
|
this.enableRevert && (h("div", { class: ['toggle-selectic', {
|
|
1511
1524
|
'selectic__label-disabled': this.disableRevert,
|
|
1512
1525
|
}] },
|
|
@@ -1514,8 +1527,8 @@ let FilterPanel = class FilterPanel extends Vue {
|
|
|
1514
1527
|
h("input", { type: "checkbox", checked: this.selectionIsExcluded, disabled: this.disableRevert, on: {
|
|
1515
1528
|
change: this.onExclude,
|
|
1516
1529
|
} }),
|
|
1517
|
-
|
|
1518
|
-
h("div", { class: "curtain-handler", on: {
|
|
1530
|
+
labels.excludeResult)))),
|
|
1531
|
+
!state.keepFilterOpen && (h("div", { class: "curtain-handler", on: {
|
|
1519
1532
|
'click.prevent.stop': this.togglePanel,
|
|
1520
1533
|
} },
|
|
1521
1534
|
h("span", { class: "fa fa-search" }),
|
|
@@ -1523,7 +1536,7 @@ let FilterPanel = class FilterPanel extends Vue {
|
|
|
1523
1536
|
'fa': true,
|
|
1524
1537
|
'fa-caret-down': this.closed,
|
|
1525
1538
|
'fa-caret-up': !this.closed,
|
|
1526
|
-
} }))));
|
|
1539
|
+
} })))));
|
|
1527
1540
|
}
|
|
1528
1541
|
};
|
|
1529
1542
|
__decorate$3([
|
|
@@ -2366,7 +2379,7 @@ let Selectic = class Selectic extends Vue {
|
|
|
2366
2379
|
/* }}} */
|
|
2367
2380
|
/* {{{ Life cycle */
|
|
2368
2381
|
created() {
|
|
2369
|
-
var _a, _b;
|
|
2382
|
+
var _a, _b, _c;
|
|
2370
2383
|
this._elementsListeners = [];
|
|
2371
2384
|
this.store = new SelecticStore({
|
|
2372
2385
|
options: this.options,
|
|
@@ -2379,8 +2392,7 @@ let Selectic = class Selectic extends Vue {
|
|
|
2379
2392
|
params: {
|
|
2380
2393
|
multiple: ((_a = this.multiple) !== null && _a !== void 0 ? _a : false) !== false,
|
|
2381
2394
|
pageSize: this.params.pageSize || 100,
|
|
2382
|
-
hideFilter: this.params.hideFilter !==
|
|
2383
|
-
? this.params.hideFilter : 'auto',
|
|
2395
|
+
hideFilter: (_b = this.params.hideFilter) !== null && _b !== void 0 ? _b : 'auto',
|
|
2384
2396
|
allowRevert: this.params.allowRevert,
|
|
2385
2397
|
allowClearSelection: this.params.allowClearSelection || false,
|
|
2386
2398
|
autoSelect: this.params.autoSelect === undefined
|
|
@@ -2395,7 +2407,7 @@ let Selectic = class Selectic extends Vue {
|
|
|
2395
2407
|
formatSelection: this.params.formatSelection,
|
|
2396
2408
|
listPosition: this.params.listPosition || 'auto',
|
|
2397
2409
|
optionBehavior: this.params.optionBehavior,
|
|
2398
|
-
isOpen: ((
|
|
2410
|
+
isOpen: ((_c = this.open) !== null && _c !== void 0 ? _c : false) !== false,
|
|
2399
2411
|
},
|
|
2400
2412
|
fetchCallback: this.params.fetchCallback,
|
|
2401
2413
|
getItemsCallback: this.params.getItemsCallback,
|
package/doc/params.md
CHANGED
|
@@ -10,13 +10,16 @@ This property is an object with several attributes which are listed below.
|
|
|
10
10
|
|
|
11
11
|
## hideFilter
|
|
12
12
|
|
|
13
|
-
Type: `boolean` | `'auto'`
|
|
13
|
+
Type: `boolean` | `'auto'` | `'open'`
|
|
14
14
|
|
|
15
15
|
If `hideFilter` is set to `true`, the handler to open the filter panel is hidden and it will not be possible to search for options.
|
|
16
16
|
|
|
17
17
|
If `hideFilter` is set to `'auto`, the handler to open the filter panel is hidden only if there is less than 10 options (when there is no scroll), and is displayed otherwise. _This is the default value_.
|
|
18
18
|
|
|
19
|
-
If `hideFilter` is set to `
|
|
19
|
+
If `hideFilter` is set to `false`, the handler to open the filter panel is always displayed.
|
|
20
|
+
|
|
21
|
+
If `hideFilter` is set to `'open'`, the handler to open or close the filter panel
|
|
22
|
+
will not be displayed and the filter panel is always open.
|
|
20
23
|
|
|
21
24
|
```html
|
|
22
25
|
<selectic
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "selectic",
|
|
3
|
-
"version": "3.0.
|
|
3
|
+
"version": "3.0.3",
|
|
4
4
|
"description": "Smart Select for VueJS 3.x",
|
|
5
5
|
"main": "dist/selectic.common.js",
|
|
6
6
|
"module": "dist/selectic.esm.js",
|
|
@@ -36,12 +36,13 @@
|
|
|
36
36
|
"test": "npm run build && tape test/**/*.spec.js"
|
|
37
37
|
},
|
|
38
38
|
"dependencies": {
|
|
39
|
-
"vtyx": "4.0.
|
|
39
|
+
"vtyx": "4.0.3"
|
|
40
40
|
},
|
|
41
41
|
"devDependencies": {
|
|
42
|
-
"
|
|
42
|
+
"@babel/types": "^7.16.7",
|
|
43
|
+
"rollup": "^2.63.0",
|
|
43
44
|
"rollup-plugin-postcss": "^3.1.8",
|
|
44
|
-
"tape": "^4.
|
|
45
|
-
"typescript": "~4.
|
|
45
|
+
"tape": "^4.14.0",
|
|
46
|
+
"typescript": "~4.5"
|
|
46
47
|
}
|
|
47
48
|
}
|
package/src/Filter.tsx
CHANGED
|
@@ -100,6 +100,10 @@ export default class FilterPanel extends Vue<Props> {
|
|
|
100
100
|
}
|
|
101
101
|
|
|
102
102
|
private togglePanel() {
|
|
103
|
+
if (this.store.state.keepFilterOpen === true) {
|
|
104
|
+
this.closed = false;
|
|
105
|
+
return;
|
|
106
|
+
}
|
|
103
107
|
this.closed = !this.closed;
|
|
104
108
|
}
|
|
105
109
|
|
|
@@ -122,7 +126,8 @@ export default class FilterPanel extends Vue<Props> {
|
|
|
122
126
|
/* {{{ Life cycle */
|
|
123
127
|
|
|
124
128
|
public mounted() {
|
|
125
|
-
|
|
129
|
+
const state = this.store.state;
|
|
130
|
+
this.closed = !state.keepFilterOpen && !state.searchText;
|
|
126
131
|
document.addEventListener('keypress', this.onKeyPressed);
|
|
127
132
|
|
|
128
133
|
this.getFocus();
|
|
@@ -135,6 +140,10 @@ export default class FilterPanel extends Vue<Props> {
|
|
|
135
140
|
/* }}} */
|
|
136
141
|
|
|
137
142
|
public render() {
|
|
143
|
+
const store = this.store;
|
|
144
|
+
const state = store.state;
|
|
145
|
+
const labels = store.data.labels;
|
|
146
|
+
|
|
138
147
|
return (
|
|
139
148
|
<div class="filter-panel">
|
|
140
149
|
<div
|
|
@@ -148,7 +157,7 @@ export default class FilterPanel extends Vue<Props> {
|
|
|
148
157
|
type="text"
|
|
149
158
|
class="form-control filter-input"
|
|
150
159
|
placeholder={this.searchPlaceholder}
|
|
151
|
-
value={
|
|
160
|
+
value={state.searchText}
|
|
152
161
|
on={{
|
|
153
162
|
'input.stop.prevent': this.onInput,
|
|
154
163
|
}}
|
|
@@ -158,7 +167,7 @@ export default class FilterPanel extends Vue<Props> {
|
|
|
158
167
|
form-control-feedback"
|
|
159
168
|
></span>
|
|
160
169
|
</div>
|
|
161
|
-
{
|
|
170
|
+
{state.multiple && (
|
|
162
171
|
<div class="toggle-selectic">
|
|
163
172
|
<label
|
|
164
173
|
class={['control-label', {
|
|
@@ -167,13 +176,13 @@ export default class FilterPanel extends Vue<Props> {
|
|
|
167
176
|
>
|
|
168
177
|
<input
|
|
169
178
|
type="checkbox"
|
|
170
|
-
checked={
|
|
179
|
+
checked={state.status.areAllSelected}
|
|
171
180
|
disabled={this.disableSelectAll}
|
|
172
181
|
on={{
|
|
173
182
|
change: this.onSelectAll,
|
|
174
183
|
}}
|
|
175
184
|
/>
|
|
176
|
-
{
|
|
185
|
+
{labels.selectAll}
|
|
177
186
|
</label>
|
|
178
187
|
</div>
|
|
179
188
|
)}
|
|
@@ -192,11 +201,13 @@ export default class FilterPanel extends Vue<Props> {
|
|
|
192
201
|
change: this.onExclude,
|
|
193
202
|
}}
|
|
194
203
|
/>
|
|
195
|
-
{
|
|
204
|
+
{labels.excludeResult}
|
|
196
205
|
</label>
|
|
197
206
|
</div>
|
|
198
207
|
)}
|
|
199
208
|
</div>
|
|
209
|
+
|
|
210
|
+
{!state.keepFilterOpen && (
|
|
200
211
|
<div class="curtain-handler"
|
|
201
212
|
on={{
|
|
202
213
|
'click.prevent.stop': this.togglePanel,
|
|
@@ -209,6 +220,7 @@ export default class FilterPanel extends Vue<Props> {
|
|
|
209
220
|
'fa-caret-up': !this.closed,
|
|
210
221
|
}}></span>
|
|
211
222
|
</div>
|
|
223
|
+
)}
|
|
212
224
|
</div>
|
|
213
225
|
);
|
|
214
226
|
}
|
package/src/Store.tsx
CHANGED
|
@@ -72,6 +72,15 @@ export type ListPosition =
|
|
|
72
72
|
/* Display the list at bottom but if there is not enough space, display it at top */
|
|
73
73
|
| 'auto';
|
|
74
74
|
|
|
75
|
+
export type HideFilter =
|
|
76
|
+
/* Display or hide the filter panel */
|
|
77
|
+
boolean
|
|
78
|
+
/* The handler to open the filter panel is hidden only if there is less
|
|
79
|
+
* than 10 options */
|
|
80
|
+
| 'auto'
|
|
81
|
+
/* The panel filter is always open */
|
|
82
|
+
| 'open';
|
|
83
|
+
|
|
75
84
|
export interface SelecticStoreStateParams {
|
|
76
85
|
/* Equivalent of <select>'s "multiple" attribute */
|
|
77
86
|
multiple?: boolean;
|
|
@@ -80,7 +89,7 @@ export interface SelecticStoreStateParams {
|
|
|
80
89
|
placeholder?: string;
|
|
81
90
|
|
|
82
91
|
/* Hide filter component when enabled */
|
|
83
|
-
hideFilter?:
|
|
92
|
+
hideFilter?: HideFilter;
|
|
84
93
|
|
|
85
94
|
/* Allow to reverse selection.
|
|
86
95
|
* If true, parent should support the selectionIsExcluded property.
|
|
@@ -203,6 +212,9 @@ export interface SelecticStoreState {
|
|
|
203
212
|
/* If true, filters and controls are hidden */
|
|
204
213
|
hideFilter: boolean;
|
|
205
214
|
|
|
215
|
+
/* If true, the filter panel is always open */
|
|
216
|
+
keepFilterOpen: boolean;
|
|
217
|
+
|
|
206
218
|
/* Allow to reverse selection.
|
|
207
219
|
* If true, parent should support the selectionIsExcluded property.
|
|
208
220
|
* If false, the action is never available.
|
|
@@ -404,6 +416,7 @@ export default class SelecticStore {
|
|
|
404
416
|
disabled: false,
|
|
405
417
|
placeholder: '',
|
|
406
418
|
hideFilter: false,
|
|
419
|
+
keepFilterOpen: false,
|
|
407
420
|
allowRevert: undefined,
|
|
408
421
|
allowClearSelection: false,
|
|
409
422
|
autoSelect: true,
|
|
@@ -625,6 +638,9 @@ export default class SelecticStore {
|
|
|
625
638
|
|
|
626
639
|
if (stateParam.hideFilter === 'auto') {
|
|
627
640
|
delete stateParam.hideFilter;
|
|
641
|
+
} else if (stateParam.hideFilter === 'open') {
|
|
642
|
+
this.state.keepFilterOpen = true;
|
|
643
|
+
delete stateParam.hideFilter;
|
|
628
644
|
}
|
|
629
645
|
|
|
630
646
|
/* Update state */
|
package/src/index.tsx
CHANGED
|
@@ -36,6 +36,7 @@ import Store, {
|
|
|
36
36
|
FormatCallback,
|
|
37
37
|
SelectionOverflow,
|
|
38
38
|
ListPosition,
|
|
39
|
+
HideFilter,
|
|
39
40
|
} from './Store';
|
|
40
41
|
import MainInput from './MainInput';
|
|
41
42
|
import ExtendedList from './ExtendedList';
|
|
@@ -55,6 +56,7 @@ export {
|
|
|
55
56
|
FormatCallback,
|
|
56
57
|
SelectionOverflow,
|
|
57
58
|
ListPosition,
|
|
59
|
+
HideFilter,
|
|
58
60
|
};
|
|
59
61
|
|
|
60
62
|
type EventType = 'input' | 'change' | 'open' | 'close' | 'focus' | 'blur' | 'item:click';
|
|
@@ -83,7 +85,7 @@ export interface ParamProps {
|
|
|
83
85
|
pageSize?: number;
|
|
84
86
|
|
|
85
87
|
/* Hide the search control */
|
|
86
|
-
hideFilter?:
|
|
88
|
+
hideFilter?: HideFilter;
|
|
87
89
|
|
|
88
90
|
/* Allow to reverse selection.
|
|
89
91
|
* If true, parent should support the selectionIsExcluded property.
|
|
@@ -774,8 +776,7 @@ export default class Selectic extends Vue<Props> {
|
|
|
774
776
|
params: {
|
|
775
777
|
multiple: (this.multiple ?? false) !== false,
|
|
776
778
|
pageSize: this.params.pageSize || 100,
|
|
777
|
-
hideFilter: this.params.hideFilter
|
|
778
|
-
? this.params.hideFilter : 'auto',
|
|
779
|
+
hideFilter: this.params.hideFilter ?? 'auto',
|
|
779
780
|
allowRevert: this.params.allowRevert, /* it can be undefined */
|
|
780
781
|
allowClearSelection: this.params.allowClearSelection || false,
|
|
781
782
|
autoSelect: this.params.autoSelect === undefined
|
|
@@ -943,6 +943,7 @@ tape.test('Store creation', (subT) => {
|
|
|
943
943
|
await sleep(0);
|
|
944
944
|
|
|
945
945
|
t.is(store.state.hideFilter, true);
|
|
946
|
+
t.is(store.state.keepFilterOpen, false);
|
|
946
947
|
t.end();
|
|
947
948
|
});
|
|
948
949
|
|
|
@@ -956,6 +957,7 @@ tape.test('Store creation', (subT) => {
|
|
|
956
957
|
await sleep(0);
|
|
957
958
|
|
|
958
959
|
t.is(store.state.hideFilter, false);
|
|
960
|
+
t.is(store.state.keepFilterOpen, false);
|
|
959
961
|
t.end();
|
|
960
962
|
});
|
|
961
963
|
|
|
@@ -994,6 +996,7 @@ tape.test('Store creation', (subT) => {
|
|
|
994
996
|
await sleep(0);
|
|
995
997
|
|
|
996
998
|
t.is(store.state.hideFilter, false);
|
|
999
|
+
t.is(store.state.keepFilterOpen, false);
|
|
997
1000
|
t.end();
|
|
998
1001
|
});
|
|
999
1002
|
});
|
|
@@ -1009,6 +1012,7 @@ tape.test('Store creation', (subT) => {
|
|
|
1009
1012
|
await sleep(0);
|
|
1010
1013
|
|
|
1011
1014
|
t.is(store.state.hideFilter, false);
|
|
1015
|
+
t.is(store.state.keepFilterOpen, false);
|
|
1012
1016
|
t.end();
|
|
1013
1017
|
});
|
|
1014
1018
|
|
|
@@ -1022,17 +1026,20 @@ tape.test('Store creation', (subT) => {
|
|
|
1022
1026
|
await sleep(0);
|
|
1023
1027
|
|
|
1024
1028
|
t.is(store.state.hideFilter, false);
|
|
1029
|
+
t.is(store.state.keepFilterOpen, false);
|
|
1025
1030
|
|
|
1026
1031
|
/* Assert it doesn't change after fetching data */
|
|
1027
1032
|
store.commit('isOpen', true);
|
|
1028
1033
|
await sleep(0);
|
|
1029
1034
|
|
|
1030
1035
|
t.is(store.state.hideFilter, false);
|
|
1036
|
+
t.is(store.state.keepFilterOpen, false);
|
|
1031
1037
|
|
|
1032
1038
|
store.commit('isOpen', false);
|
|
1033
1039
|
await sleep(0);
|
|
1034
1040
|
|
|
1035
1041
|
t.is(store.state.hideFilter, false);
|
|
1042
|
+
t.is(store.state.keepFilterOpen, false);
|
|
1036
1043
|
t.end();
|
|
1037
1044
|
});
|
|
1038
1045
|
});
|
|
@@ -1089,6 +1096,49 @@ tape.test('Store creation', (subT) => {
|
|
|
1089
1096
|
t.end();
|
|
1090
1097
|
});
|
|
1091
1098
|
});
|
|
1099
|
+
|
|
1100
|
+
st.test('having value "open"', (sTest) => {
|
|
1101
|
+
sTest.test('should show filter with few options', async (t) => {
|
|
1102
|
+
const store = new Store({
|
|
1103
|
+
options: getOptions(3),
|
|
1104
|
+
params: {
|
|
1105
|
+
hideFilter: 'open',
|
|
1106
|
+
},
|
|
1107
|
+
});
|
|
1108
|
+
await sleep(0);
|
|
1109
|
+
|
|
1110
|
+
t.is(store.state.hideFilter, false);
|
|
1111
|
+
t.is(store.state.keepFilterOpen, true);
|
|
1112
|
+
t.end();
|
|
1113
|
+
});
|
|
1114
|
+
|
|
1115
|
+
sTest.test('should show filter with dynamic options', async (t) => {
|
|
1116
|
+
const store = new Store({
|
|
1117
|
+
fetchCallback: buildFetchCb({ total: 5 }),
|
|
1118
|
+
params: {
|
|
1119
|
+
hideFilter: 'open',
|
|
1120
|
+
},
|
|
1121
|
+
});
|
|
1122
|
+
await sleep(0);
|
|
1123
|
+
|
|
1124
|
+
t.is(store.state.hideFilter, false);
|
|
1125
|
+
t.is(store.state.keepFilterOpen, true);
|
|
1126
|
+
|
|
1127
|
+
/* Assert it doesn't change after fetching data */
|
|
1128
|
+
store.commit('isOpen', true);
|
|
1129
|
+
await sleep(0);
|
|
1130
|
+
|
|
1131
|
+
t.is(store.state.hideFilter, false);
|
|
1132
|
+
t.is(store.state.keepFilterOpen, true);
|
|
1133
|
+
|
|
1134
|
+
store.commit('isOpen', false);
|
|
1135
|
+
await sleep(0);
|
|
1136
|
+
|
|
1137
|
+
t.is(store.state.hideFilter, false);
|
|
1138
|
+
t.is(store.state.keepFilterOpen, true);
|
|
1139
|
+
t.end();
|
|
1140
|
+
});
|
|
1141
|
+
});
|
|
1092
1142
|
});
|
|
1093
1143
|
|
|
1094
1144
|
subT.test('"optionBehavior" property', (st) => {
|
package/test/helper.js
CHANGED
package/types/Store.d.ts
CHANGED
|
@@ -37,10 +37,11 @@ export declare type GetCallback = (_ids: OptionId[]) => Promise<OptionValue[]>;
|
|
|
37
37
|
export declare type FormatCallback = (_option: OptionItem) => OptionItem;
|
|
38
38
|
export declare type SelectionOverflow = 'collapsed' | 'multiline';
|
|
39
39
|
export declare type ListPosition = 'bottom' | 'top' | 'auto';
|
|
40
|
+
export declare type HideFilter = boolean | 'auto' | 'open';
|
|
40
41
|
export interface SelecticStoreStateParams {
|
|
41
42
|
multiple?: boolean;
|
|
42
43
|
placeholder?: string;
|
|
43
|
-
hideFilter?:
|
|
44
|
+
hideFilter?: HideFilter;
|
|
44
45
|
allowRevert?: boolean;
|
|
45
46
|
allowClearSelection?: boolean;
|
|
46
47
|
pageSize?: number;
|
|
@@ -83,6 +84,7 @@ export interface SelecticStoreState {
|
|
|
83
84
|
disabled: boolean;
|
|
84
85
|
placeholder: string;
|
|
85
86
|
hideFilter: boolean;
|
|
87
|
+
keepFilterOpen: boolean;
|
|
86
88
|
allowRevert?: boolean;
|
|
87
89
|
allowClearSelection: boolean;
|
|
88
90
|
autoSelect: boolean;
|
|
@@ -147,6 +149,7 @@ export default class SelecticStore {
|
|
|
147
149
|
disabled: boolean;
|
|
148
150
|
placeholder: string;
|
|
149
151
|
hideFilter: boolean;
|
|
152
|
+
keepFilterOpen: boolean;
|
|
150
153
|
allowRevert?: boolean | undefined;
|
|
151
154
|
allowClearSelection: boolean;
|
|
152
155
|
autoSelect: boolean;
|
package/types/index.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { Vue, h } from 'vtyx';
|
|
2
2
|
import './css/selectic.css';
|
|
3
|
-
import { OptionProp, OptionId, StrictOptionId, GroupValue, SelectedValue, FetchCallback, GetCallback, PartialMessages, OptionValue, OptionItem, FormatCallback, SelectionOverflow, ListPosition } from './Store';
|
|
3
|
+
import { OptionProp, OptionId, StrictOptionId, GroupValue, SelectedValue, FetchCallback, GetCallback, PartialMessages, OptionValue, OptionItem, FormatCallback, SelectionOverflow, ListPosition, HideFilter } from './Store';
|
|
4
4
|
import MainInput from './MainInput';
|
|
5
5
|
import ExtendedList from './ExtendedList';
|
|
6
|
-
export { GroupValue, OptionValue, OptionItem, OptionProp, OptionId, StrictOptionId, SelectedValue, PartialMessages, GetCallback, FetchCallback, FormatCallback, SelectionOverflow, ListPosition, };
|
|
6
|
+
export { GroupValue, OptionValue, OptionItem, OptionProp, OptionId, StrictOptionId, SelectedValue, PartialMessages, GetCallback, FetchCallback, FormatCallback, SelectionOverflow, ListPosition, HideFilter, };
|
|
7
7
|
declare type EventType = 'input' | 'change' | 'open' | 'close' | 'focus' | 'blur' | 'item:click';
|
|
8
8
|
export interface EventOptions {
|
|
9
9
|
instance: Selectic;
|
|
@@ -17,7 +17,7 @@ export interface ParamProps {
|
|
|
17
17
|
fetchCallback?: FetchCallback;
|
|
18
18
|
getItemsCallback?: GetCallback;
|
|
19
19
|
pageSize?: number;
|
|
20
|
-
hideFilter?:
|
|
20
|
+
hideFilter?: HideFilter;
|
|
21
21
|
allowRevert?: boolean;
|
|
22
22
|
allowClearSelection?: boolean;
|
|
23
23
|
autoSelect?: boolean;
|