Skip to content

Commit

Permalink
enhancement(Autocomplete) allow default option in single and multisel…
Browse files Browse the repository at this point in the history
…ect #479
  • Loading branch information
gselderslaghs committed Jan 1, 2025
1 parent 65ddf18 commit 248d4a1
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/autocomplete.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,10 @@ export interface AutocompleteOptions extends BaseOptions {
* @default {}
*/
dropdownOptions: Partial<DropdownOptions>;
/**
* Predefined selected values
*/
selected: number[];
}

const _defaults: AutocompleteOptions = {
Expand All @@ -90,7 +94,8 @@ const _defaults: AutocompleteOptions = {
);
},
maxDropDownHeight: '300px',
allowUnsafeHTML: false
allowUnsafeHTML: false,
selected: []
};

export class Autocomplete extends Component<AutocompleteOptions> {
Expand Down Expand Up @@ -124,7 +129,7 @@ export class Autocomplete extends Component<AutocompleteOptions> {
this.count = 0;
this.activeIndex = -1;
this.oldVal = '';
this.selectedValues = [];
this.selectedValues = this.selectedValues || this.options.selected.map((value) => <AutocompleteData>{ id: value }) || [];
this.menuItems = this.options.data || [];
this.$active = null;
this._mousedown = false;
Expand Down Expand Up @@ -378,6 +383,9 @@ export class Autocomplete extends Component<AutocompleteOptions> {
'display:grid; grid-auto-flow: column; user-select: none; align-items: center;'
);
// Checkbox
if(!this.options.isMultiSelect && this.options.selected) {
this.selectOption(this.selectedValues.map((value) => value.id)[0]);
}
if (this.options.isMultiSelect) {
item.innerHTML = `
<div class="item-selection" style="text-align:center;">
Expand Down

0 comments on commit 248d4a1

Please sign in to comment.