Skip to content

Commit bc9dca1

Browse files
committed
refactor: add SCSS variables
1 parent 7b3b080 commit bc9dca1

File tree

4 files changed

+317
-276
lines changed

4 files changed

+317
-276
lines changed

js/src/select.js

Lines changed: 35 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,7 @@ class Select {
205205
SelectorEngine.findOne(SELECTOR_INPUT, this._clone).focus()
206206
}
207207
})
208+
208209
}
209210

210211
_getConfig(config, update) {
@@ -333,6 +334,10 @@ class Select {
333334
div.classList.add(CLASS_NAME_SELECT_INLINE)
334335
}
335336

337+
if (this._config.selectionType === 'tags') {
338+
div.classList.add(CLASS_NAME_SELECTION_TAGS)
339+
}
340+
336341
this._clone = div
337342
this._element.parentNode.insertBefore(div, this._element.nextSibling)
338343
if (!this._config.inline || (this._config.inline && this._config.selection)) {
@@ -352,9 +357,6 @@ class Select {
352357
_createSelection() {
353358
const span = document.createElement('span')
354359
span.classList.add(CLASS_NAME_SELECTION)
355-
if (this._config.selectionType === 'tags') {
356-
span.classList.add(CLASS_NAME_SELECTION_TAGS)
357-
}
358360
this._clone.append(span)
359361

360362
this._updateSelection()
@@ -364,25 +366,14 @@ class Select {
364366
_createSearchInput() {
365367
const input = document.createElement('input')
366368
input.classList.add(CLASS_NAME_SEARCH)
367-
// if (this._selection.length === 0) {
368-
// input.placeholder = this._config.searchPlaceholder
369-
// }
370369

371-
// if (this._selection.length > 0 && !this._config.multiple) {
372-
// input.placeholder = this._selection[0].text
373-
// this._selectionElement.style.display = 'none'
370+
// if (!this._config.inline && this._selection.length > 0 && (this._config.selectionType === 'tags' || this._config.selectionType === 'text')) {
371+
// input.size = 2
374372
// }
375-
376-
// if (this._selection.length > 0 && this._config.multiple) {
377-
// input.placeholder = ''
378-
// }
379-
380-
if (this._selection.length > 0 && (this._config.selectionType === 'tags' || this._config.selectionType === 'text')) {
381-
input.size = 2
382-
}
373+
this._searchElement = input
374+
this._updateSearchSize()
383375

384376
this._clone.append(input)
385-
this._searchElement = input
386377
}
387378

388379
_createOptionsContainer() {
@@ -402,11 +393,6 @@ class Select {
402393
optionDiv.dataset.value = String(option.value)
403394
optionDiv.tabIndex = 0
404395
optionDiv.innerHTML = option.text
405-
// if (option.selected) {
406-
// optionDiv.classList.add(CLASS_NAME_SELECTED)
407-
// // this._selectionAdd(String(option.value), option.text)
408-
// }
409-
410396
parentElement.append(optionDiv)
411397
}
412398

@@ -431,7 +417,7 @@ class Select {
431417
tag.dataset.value = value
432418
tag.innerHTML = text
433419

434-
const closeBtn = document.createElement('button')
420+
const closeBtn = document.createElement('span')
435421
closeBtn.classList.add(CLASS_NAME_TAG_DELETE, 'close')
436422
closeBtn.setAttribute('aria-label', 'Close')
437423
closeBtn.innerHTML = '<span aria-hidden="true">&times;</span>'
@@ -490,6 +476,7 @@ class Select {
490476

491477
this._updateSelection()
492478
this._updateSearch()
479+
this._updateSearchSize()
493480
}
494481

495482
_selectionAdd(value, text) {
@@ -559,6 +546,10 @@ class Select {
559546
}
560547

561548
_updateSearch() {
549+
if (!this._config.search) {
550+
return
551+
}
552+
562553
if (this._selection.length === 0 && (this._config.selectionType === 'tags' || this._config.selectionType === 'text')) {
563554
this._searchElement.removeAttribute('size')
564555
}
@@ -592,6 +583,17 @@ class Select {
592583
}
593584
}
594585

586+
_updateSearchSize(size = 2) {
587+
if (!this._config.inline && this._selection.length > 0 && (this._config.selectionType === 'tags' || this._config.selectionType === 'text')) {
588+
this._searchElement.size = size
589+
return
590+
}
591+
592+
if (this._selection.length === 0 && (this._config.selectionType === 'tags' || this._config.selectionType === 'text')) {
593+
this._searchElement.size.removeAttribute('size')
594+
}
595+
}
596+
595597
// .c-select-selections
596598

597599
_selectOption(value) {
@@ -635,14 +637,16 @@ class Select {
635637
if (element) {
636638
this.search(element.value)
637639

638-
if (this._selection.length > 0 && (this._config.selectionType === 'tags' || this._config.selectionType === 'text')) {
639-
element.size = element.value.length + 1
640-
return
641-
}
640+
this._updateSearchSize(element.value.length + 1)
642641

643-
if (this._selection.length === 0 && (this._config.selectionType === 'tags' || this._config.selectionType === 'text')) {
644-
element.removeAttribute('size')
645-
}
642+
// if (!this._config.inline && this._selection.length > 0 && (this._config.selectionType === 'tags' || this._config.selectionType === 'text')) {
643+
// element.size = element.value.length + 1
644+
// return
645+
// }
646+
647+
// if (this._selection.length === 0 && (this._config.selectionType === 'tags' || this._config.selectionType === 'text')) {
648+
// element.removeAttribute('size')
649+
// }
646650
}
647651
}
648652

0 commit comments

Comments
 (0)