Skip to content

Commit 3a489ed

Browse files
authored
fix: add missing blur event and option types (#386)
1 parent 717b3d6 commit 3a489ed

File tree

3 files changed

+7
-6
lines changed

3 files changed

+7
-6
lines changed

packages/multiple-select-vanilla/src/MultipleSelectInstance.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ export class MultipleSelectInstance {
282282
// listen to Tab and call `onBlur` when that happens
283283
this._bindEventService.bind(this.dropElm, 'keyup', ((e: KeyboardEvent) => {
284284
if (e.code === 'Tab') {
285-
this.options.onBlur();
285+
this.options.onBlur(e);
286286
}
287287
}) as EventListener);
288288
}
@@ -1628,7 +1628,7 @@ export class MultipleSelectInstance {
16281628
const options = Object.assign({}, this.options);
16291629
delete options.data;
16301630

1631-
return returnDeepCopy ? deepCopy(options) : this.options;
1631+
return returnDeepCopy ? deepCopy<MultipleSelectOption>(options) : this.options;
16321632
}
16331633

16341634
refreshOptions(options: Partial<MultipleSelectOption>) {

packages/multiple-select-vanilla/src/models/multipleSelectOption.interface.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ export interface ClickedOption extends ClickedItem<'option'> {
3030
}
3131

3232
export type CloseReason =
33+
| 'blur'
3334
| 'body.click'
3435
| 'hover.mouseout'
3536
| 'key.shift+tab'
@@ -308,7 +309,7 @@ export interface MultipleSelectOption extends MultipleSelectLocale {
308309
onFocus: () => void;
309310

310311
/** Bind an event handler to the "blur" */
311-
onBlur: () => void;
312+
onBlur: (e?: KeyboardEvent | FocusEvent) => void;
312313

313314
/**
314315
* Fires when any option/group selections changes.

packages/multiple-select-vanilla/src/utils/utils.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,20 +17,20 @@ export function compareObjects(objectA: any, objectB: any, compareLength = false
1717
}
1818

1919
/** make deep copy clone of an object */
20-
export function deepCopy(obj: any): any {
20+
export function deepCopy<T = any>(obj: T): T {
2121
if (typeof obj !== 'object' || obj === null) {
2222
return obj;
2323
}
2424

2525
if (Array.isArray(obj)) {
26-
return obj.map(deepCopy);
26+
return obj.map(deepCopy) as T;
2727
}
2828

2929
if (typeof obj === 'function') {
3030
return obj;
3131
}
3232

33-
return Object.fromEntries(Object.entries(obj).map(([key, value]) => [key, deepCopy(value)]));
33+
return Object.fromEntries(Object.entries(obj).map(([key, value]) => [key, deepCopy(value)])) as T;
3434
}
3535

3636
export function isDefined(val: any) {

0 commit comments

Comments
 (0)