@ryusei/code
Version:
<div align="center"> <a href="https://code.ryuseijs.com"> <img alt="RyuseiCode" src="https://code.ryuseijs.com/images/svg/logo.svg" width="70"> </a>
16 lines (13 loc) • 348 B
text/typescript
import { isFunction } from '../../type/type';
/**
* Focuses the provided element without scrolling the ascendant element.
*
* @param elm - An element to focus.
*/
export function focus( elm: HTMLElement ): void {
if ( isFunction( elm[ 'setActive' ] ) ) {
elm[ 'setActive' ]();
} else {
elm.focus( { preventScroll: true } );
}
}