add focus tool; time input: refactor away from bind:ref
This commit is contained in:
@@ -69,3 +69,21 @@ export const getValue = (option: Option): string => {
|
||||
return option.value;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* targetMust returns the target of an event coerced to a particular type and
|
||||
* throws an error if the target does not exist or is not connected.
|
||||
*
|
||||
* @returns The target element coerced to a particular type.
|
||||
* @throws Will throw an error if the target is null or not connected to the DOM.
|
||||
*/
|
||||
export function targetMust<T extends HTMLElement>(event: Event): T {
|
||||
const target = event.target as T | null;
|
||||
if (!target) {
|
||||
throw new Error('Event target is null');
|
||||
}
|
||||
if (!target.isConnected) {
|
||||
throw new Error('Event target is not connected to the DOM');
|
||||
}
|
||||
return target;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user