Skip to content

Commit ae8cf0f

Browse files
authored
Merge pull request #1035 from Sysvale/feature/select-deep-search
feat: adiciona busca por termos individuais no select
2 parents f2b7475 + 28d09ee commit ae8cf0f

File tree

3 files changed

+33
-3
lines changed

3 files changed

+33
-3
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@sysvale/cuida",
3-
"version": "3.150.1",
3+
"version": "3.151.0",
44
"description": "A design system built by Sysvale, using storybook and Vue components",
55
"repository": {
66
"type": "git",

src/components/Select.vue

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,15 @@ const props = defineProps({
170170
default: false,
171171
required: false,
172172
},
173+
/**
174+
* Indica se a busca deve levar em consideração argumentos compostos.
175+
* Só tem efeito se a prop `searchable` for `true`.
176+
*/
177+
deepSearch: {
178+
type: Boolean,
179+
default: false,
180+
required: false,
181+
},
173182
/**
174183
* @deprecated Define a largura do Select. As opções são 'thin', 'default' e 'wide'.
175184
*/
@@ -412,13 +421,34 @@ function filterOptions(value) {
412421
}
413422
414423
const sanitizedString = removeAccents(String(value) || '');
415-
const regexExp = new RegExp(sanitizedString, 'i');
424+
425+
if (props.deepSearch) {
426+
deepOptionSearch(sanitizedString);
427+
} else {
428+
simpleOptionSearch(sanitizedString);
429+
}
430+
}
431+
432+
function simpleOptionSearch(sanitizedSearchValue) {
433+
const regexExp = new RegExp(sanitizedSearchValue, 'i');
416434
417435
localOptions.value = pristineOptions.value.filter(
418436
(option) => removeAccents(option[props.optionsField]).search(regexExp) >= 0,
419437
);
420438
}
421439
440+
function deepOptionSearch(sanitizedSearchValue) {
441+
const searchArray = sanitizedSearchValue.toLowerCase().split(' ');
442+
443+
localOptions.value = pristineOptions.value.filter(
444+
(option) => {
445+
return searchArray.reduce((acc, curr) => (
446+
acc = acc && removeAccents(option[props.optionsField]).toLowerCase().includes(curr)
447+
), true);
448+
}
449+
)
450+
}
451+
422452
function activeSelection() {
423453
if (props.disabled) return;
424454

src/tests/__snapshots__/Select.spec.js.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
exports[`Select > renders correctly 1`] = `
44
"<div data-v-96b70cc4="" class="select" id="select-input">
55
<div data-v-96b70cc4="" class="select__container select__container--fit">
6-
<div data-v-82c69faf="" data-v-96b70cc4="" class="base-input__container select__input--undefined select__input--fit" options="[object Object],[object Object]" searchable="false" width="" optionsfield="value" returnvalue="false" mobile="false" addable="false" onkeypress="return false;">
6+
<div data-v-82c69faf="" data-v-96b70cc4="" class="base-input__container select__input--undefined select__input--fit" options="[object Object],[object Object]" searchable="false" deepsearch="false" width="" optionsfield="value" returnvalue="false" mobile="false" addable="false" onkeypress="return false;">
77
<!--v-if--><label data-v-c1eb01da="" data-v-82c69faf="" class="label">
88
<div data-v-c2ac4e6d="" data-v-c1eb01da="" class="flexbox label__content">
99
<!-- @slot Slot com o conteúdo interno do FlexBox -->label

0 commit comments

Comments
 (0)