@roqueform/ref-plugin
Version:
Associates Roqueform fields with DOM elements.
47 lines (46 loc) • 1.69 kB
TypeScript
import { PluginInjector } from 'roqueform';
/**
* The plugin added to fields by the {@link refPlugin}.
*/
export interface RefPlugin {
/**
* The DOM element associated with the field, or `null` if there's no associated element.
*/
element: Element | null;
/**
* `true` if {@link element the DOM element} is focused, or `false` otherwise.
*/
readonly isFocused: boolean;
/**
* Associates the field with the {@link element DOM element}.
*/
ref(element: Element | null): void;
/**
* Scrolls the field element's ancestor containers such that the field element is visible to the user.
*
* @param alignToTop If `true`, the top of the element will be aligned to the top of the visible area of the
* scrollable ancestor, otherwise element will be aligned to the bottom of the visible area of the scrollable
* ancestor.
*/
scrollIntoView(alignToTop?: boolean): void;
/**
* Scrolls the field element's ancestor containers such that the field element is visible to the user.
*
* @param options The [scroll options](https://developer.mozilla.org/en-US/docs/Web/API/Element/scrollIntoView#sect1).
*/
scrollIntoView(options?: ScrollIntoViewOptions): void;
/**
* Focuses the field element.
*
* @param options The [scroll options](https://developer.mozilla.org/en-US/docs/Web/API/Element/scrollIntoView#sect1).
*/
focus(options?: FocusOptions): void;
/**
* Blurs the field element.
*/
blur(): void;
}
/**
* Enables field-element association and simplifies focus control.
*/
export declare function refPlugin(): PluginInjector<RefPlugin>;