Skip to content

Commit

Permalink
chore: add missing TS types
Browse files Browse the repository at this point in the history
  • Loading branch information
ghiscoding committed Nov 10, 2023
1 parent 23ad751 commit 3dbae89
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
18 changes: 9 additions & 9 deletions lib/src/MultipleSelectInstance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ export class MultipleSelectInstance {
this.elm.childNodes.forEach((elm) => {
const row = this.initRow(elm as HTMLOptionElement);
if (row) {
data.push(row);
data.push(row as OptionRowData);
}
});

Expand All @@ -296,10 +296,10 @@ export class MultipleSelectInstance {
}

protected initRow(elm: HTMLOptionElement, groupDisabled?: boolean) {
const row: any = {};
const row = {} as OptionRowData | OptGroupRowData;
if (elm.tagName?.toLowerCase() === 'option') {
row.type = 'option';
row.text = this.options.textTemplate(elm);
(row as OptionRowData).text = this.options.textTemplate(elm);
row.value = elm.value;
row.visible = true;
row.selected = Boolean(elm.selected);
Expand All @@ -323,7 +323,7 @@ export class MultipleSelectInstance {

if (elm.tagName?.toLowerCase() === 'optgroup') {
row.type = 'optgroup';
row.label = this.options.labelTemplate(elm);
(row as OptGroupRowData).label = this.options.labelTemplate(elm);
row.visible = true;
row.selected = Boolean(elm.selected);
row.disabled = elm.disabled;
Expand All @@ -333,7 +333,7 @@ export class MultipleSelectInstance {
}

elm.childNodes.forEach((childNode) => {
(row as OptGroupRowData).children.push(this.initRow(childNode as HTMLOptionElement, row.disabled));
(row as OptGroupRowData).children.push(this.initRow(childNode as HTMLOptionElement, row.disabled) as OptionRowData);
});

return row;
Expand Down Expand Up @@ -1166,16 +1166,16 @@ export class MultipleSelectInstance {

setSelects(values: any[], type = 'value', ignoreTrigger = false) {
let hasChanged = false;
const _setSelects = (rows: any[]) => {
const _setSelects = (rows: Array<OptionRowData | OptGroupRowData>) => {
for (const row of rows) {
let selected = false;
if (type === 'text') {
const divElm = document.createElement('div');
this.applyAsTextOrHtmlWhenEnabled(divElm, row.text);
this.applyAsTextOrHtmlWhenEnabled(divElm, (row as OptionRowData).text);
selected = values.includes(divElm.textContent?.trim() ?? '');
} else {
selected = values.includes(row._value || row.value);
if (!selected && row.value === `${+row.value}`) {
if (!selected && row.value === `${+(row as OptionRowData).value}`) {
selected = values.includes(+row.value);
}
}
Expand Down Expand Up @@ -1261,7 +1261,7 @@ export class MultipleSelectInstance {

protected _checkGroup(group: any, checked: boolean, ignoreUpdate?: boolean) {
group.selected = checked;
group.children.forEach((row: any) => {
group.children.forEach((row: OptionRowData) => {
if (row && !row.disabled && !row.divider && (ignoreUpdate || row.visible)) {
row.selected = checked;
}
Expand Down
2 changes: 2 additions & 0 deletions lib/src/interfaces/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,15 @@ export interface HtmlStruct {
export interface OptionRowData {
text: string;
value: string | number | boolean;
html?: HTMLElement;
classes?: string;
divider?: string;
disabled?: boolean;
selected?: boolean | number;
visible?: boolean | string;
title?: string;
type?: 'option' | 'optgroup';
_data?: { divider?: string };
_key?: string;
_value?: string | number | boolean;
}
Expand Down

0 comments on commit 3dbae89

Please sign in to comment.