Skip to content

Commit 883d828

Browse files
committed
Restructure the render functions
1 parent ac75df4 commit 883d828

3 files changed

Lines changed: 102 additions & 67 deletions

File tree

src/includes/vscode-select/vscode-select-base.ts

Lines changed: 2 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ export class VscodeSelectBase extends VscElement {
246246
protected _isPlaceholderOptionActive = false;
247247

248248
@state()
249-
private _isBeingFiltered = false;
249+
protected _isBeingFiltered = false;
250250

251251
@state()
252252
protected _optionListScrollPos = 0;
@@ -722,69 +722,8 @@ export class VscodeSelectBase extends VscElement {
722722
return html`${nothing}`;
723723
}
724724

725-
private _renderMultiSelectLabel() {
726-
switch (this._opts.selectedIndexes.length) {
727-
case 0:
728-
return html`<span class="select-face-badge no-item"
729-
>No items selected</span
730-
>`;
731-
case 1:
732-
return html`<span class="select-face-badge">1 item selected</span>`;
733-
default:
734-
return html`<span class="select-face-badge"
735-
>${this._opts.selectedIndexes.length} items selected</span
736-
>`;
737-
}
738-
}
739-
740725
protected _renderComboboxFace(): TemplateResult {
741-
let inputVal = '';
742-
743-
if (this._isBeingFiltered) {
744-
inputVal = this._opts.filterPattern;
745-
} else {
746-
const op = this._opts.getSelectedOption();
747-
inputVal = op?.label ?? '';
748-
}
749-
750-
const activeDescendant =
751-
this._opts.activeIndex > -1 ? `op-${this._opts.activeIndex}` : '';
752-
const expanded = this.open ? 'true' : 'false';
753-
754-
return html`
755-
<div class="combobox-face face">
756-
${this._multiple ? this._renderMultiSelectLabel() : nothing}
757-
<input
758-
aria-activedescendant=${activeDescendant}
759-
aria-autocomplete="list"
760-
aria-controls="select-listbox"
761-
aria-expanded=${expanded}
762-
aria-haspopup="listbox"
763-
aria-label=${ifDefined(this.label)}
764-
class="combobox-input"
765-
role="combobox"
766-
spellcheck="false"
767-
type="text"
768-
autocomplete="off"
769-
.value=${inputVal}
770-
@focus=${this._onComboboxInputFocus}
771-
@blur=${this._onComboboxInputBlur}
772-
@input=${this._onComboboxInputInput}
773-
@click=${this._onComboboxInputClick}
774-
@keydown=${this._onComboboxInputSpaceKeyDown}
775-
>
776-
<button
777-
aria-label="Open the list of options"
778-
class="combobox-button"
779-
type="button"
780-
@click=${this._onComboboxButtonClick}
781-
@keydown=${this._onComboboxButtonKeyDown}
782-
tabindex="-1"
783-
>
784-
${chevronDownIcon}
785-
</button>
786-
</div>
787-
`;
726+
return html`${nothing}`;
788727
}
789728

790729
protected _renderDropdownControls(): TemplateResult {

src/vscode-multi-select/vscode-multi-select.ts

Lines changed: 51 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -346,6 +346,56 @@ export class VscodeMultiSelect
346346
}
347347
}
348348

349+
protected override _renderComboboxFace(): TemplateResult {
350+
let inputVal = '';
351+
352+
if (this._isBeingFiltered) {
353+
inputVal = this._opts.filterPattern;
354+
} else {
355+
const op = this._opts.getSelectedOption();
356+
inputVal = op?.label ?? '';
357+
}
358+
359+
const activeDescendant =
360+
this._opts.activeIndex > -1 ? `op-${this._opts.activeIndex}` : '';
361+
const expanded = this.open ? 'true' : 'false';
362+
363+
return html`
364+
<div class="combobox-face face">
365+
${this._multiple ? this._renderLabel() : nothing}
366+
<input
367+
aria-activedescendant=${activeDescendant}
368+
aria-autocomplete="list"
369+
aria-controls="select-listbox"
370+
aria-expanded=${expanded}
371+
aria-haspopup="listbox"
372+
aria-label=${ifDefined(this.label)}
373+
class="combobox-input"
374+
role="combobox"
375+
spellcheck="false"
376+
type="text"
377+
autocomplete="off"
378+
.value=${inputVal}
379+
@focus=${this._onComboboxInputFocus}
380+
@blur=${this._onComboboxInputBlur}
381+
@input=${this._onComboboxInputInput}
382+
@click=${this._onComboboxInputClick}
383+
@keydown=${this._onComboboxInputSpaceKeyDown}
384+
>
385+
<button
386+
aria-label="Open the list of options"
387+
class="combobox-button"
388+
type="button"
389+
@click=${this._onComboboxButtonClick}
390+
@keydown=${this._onComboboxButtonKeyDown}
391+
tabindex="-1"
392+
>
393+
${chevronDownIcon}
394+
</button>
395+
</div>
396+
`;
397+
}
398+
349399
protected override _renderSelectFace(): TemplateResult {
350400
const activeDescendant =
351401
this._opts.activeIndex > -1 ? `op-${this._opts.activeIndex}` : '';
@@ -405,10 +455,7 @@ export class VscodeMultiSelect
405455

406456
override render(): TemplateResult {
407457
return html`
408-
<div
409-
class="multi-select"
410-
aria-label=${ifDefined(this.label ?? undefined)}
411-
>
458+
<div class="multi-select">
412459
<slot class="main-slot" @slotchange=${this._onSlotChange}></slot>
413460
${this.combobox ? this._renderComboboxFace() : this._renderSelectFace()}
414461
${this._renderDropdown()}

src/vscode-single-select/vscode-single-select.ts

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -374,6 +374,55 @@ export class VscodeSingleSelect
374374
`;
375375
}
376376

377+
protected override _renderComboboxFace(): TemplateResult {
378+
let inputVal = '';
379+
380+
if (this._isBeingFiltered) {
381+
inputVal = this._opts.filterPattern;
382+
} else {
383+
const op = this._opts.getSelectedOption();
384+
inputVal = op?.label ?? '';
385+
}
386+
387+
const activeDescendant =
388+
this._opts.activeIndex > -1 ? `op-${this._opts.activeIndex}` : '';
389+
const expanded = this.open ? 'true' : 'false';
390+
391+
return html`
392+
<div class="combobox-face face">
393+
<input
394+
aria-activedescendant=${activeDescendant}
395+
aria-autocomplete="list"
396+
aria-controls="select-listbox"
397+
aria-expanded=${expanded}
398+
aria-haspopup="listbox"
399+
aria-label=${ifDefined(this.label)}
400+
class="combobox-input"
401+
role="combobox"
402+
spellcheck="false"
403+
type="text"
404+
autocomplete="off"
405+
.value=${inputVal}
406+
@focus=${this._onComboboxInputFocus}
407+
@blur=${this._onComboboxInputBlur}
408+
@input=${this._onComboboxInputInput}
409+
@click=${this._onComboboxInputClick}
410+
@keydown=${this._onComboboxInputSpaceKeyDown}
411+
>
412+
<button
413+
aria-label="Open the list of options"
414+
class="combobox-button"
415+
type="button"
416+
@click=${this._onComboboxButtonClick}
417+
@keydown=${this._onComboboxButtonKeyDown}
418+
tabindex="-1"
419+
>
420+
${chevronDownIcon}
421+
</button>
422+
</div>
423+
`;
424+
}
425+
377426
override render(): TemplateResult {
378427
return html`
379428
<div class="single-select">

0 commit comments

Comments
 (0)