@microsoft/windows-admin-center-sdk
Version:
Microsoft - Windows Admin Center Shell
453 lines (452 loc) • 18.4 kB
TypeScript
export interface DomElementProperties {
isForm: boolean;
withinForm: boolean;
isTrap: boolean;
withinTrap: boolean;
isZone: boolean;
withinZone: boolean;
withinZoneWithinForm: boolean;
currentZone: HTMLElement;
currentTrap: HTMLElement;
currentForm: HTMLElement;
}
/**
* DOM class
* @dynamic
*/
export declare class Dom {
static getElementProperties(element: HTMLElement, properties?: DomElementProperties): DomElementProperties;
static allowCustomArrowKeyFunctionality(properties: DomElementProperties): boolean;
static allowCustomHomeEndKeyFunctionality(element: HTMLElement, properties: DomElementProperties): boolean;
/**
* gets all body elements on the page
*/
static getAllBodys(): HTMLElement[];
/**
* Gets a CSS property value
* @param element The Element
* @param property - The CSS property name
* @returns The value of the CSS property (type depends on property retrieved)
*/
static getStyle(element: HTMLElement, property: string): any;
/**
* Gets the classes applied to an element
* @param element The Element
* @returns The classes currently applied to the element
*/
static getClasses(element: HTMLElement): any;
/**
* Determines is an element is disabled via the 'disabled' attribute
* @param element The element to start from.
*/
static isDisabled(element: HTMLElement): boolean;
/**
* Determines is an element is hidden via css with "display: none"
* @param element The element to start from.
*/
static isNotDisplayed(element: HTMLElement): boolean;
/**
* Determines is an element is hidden via css with "visibility: hidden"
* @param element The element to start from.
*/
static isHidden(element: HTMLElement): boolean;
/**
* Returns the first element in the current elements ancestory that is focusable.
*
* 'Focusable' is defined as the following:
* - input, select, textarea, button, object
* - anchor with href
* - have a non-negative tab index
*
* An element is not focusable if any of the following is true (even if it meets a condition above)
* - negative tab index
* - disabled
* - display: none
* - visibility: hidden
*
* @param element The element to start from.
* @return true if focus possible
*/
static isFocusable(element: HTMLElement, includeNegativeTabIndex?: boolean): boolean;
/**
* Returns true if the element could be focusable.
*
* An element that can be focused is the following:
* - input, select, textarea, button, object
* - anchor with href
* - have a non-negative tab index
*
* This method will determine if the element has one of these conditions even if the the element
* is not displayed, visible, enabled, or having a positive z-index.
*
* @param element The element to start from.
* @return true if focus possible.
*/
static isFocusPossible(element: HTMLElement, includeNegativeTabIndex?: boolean): boolean;
private static checkFocusableConditions;
/**
* Returns the first element in the current elements ancestry that is focusable.
* Will return the element itself if it is focusable
* @param element The element to start from.
* @return the first focusable ancestor of the element
*/
static getFocusableAncestor(element: HTMLElement): HTMLElement;
/**
* find an element in a particular position with a specific condition relative to input element
* Does a DFS for this element relative the ancestor zone of input element
* @param element The current element
* @param condition The function to check the kind of element we are looking for
* @param position The ElementPosition of the desired element relative to input element
*/
static findElementFromAncestorZoneDFS(element: HTMLElement, condition: (element: HTMLElement) => boolean, position: ElementPosition): HTMLElement;
/**
* find an element in a particular position with a specific condition relative to input element
* Does a DFS for this element relative the ancestor trap of input element
* @param element The current element
* @param condition The function to check the kind of element we are looking for
* @param position The ElementPosition of the desired element relative to input element
*/
static findElementFromAncestorTrapDFS(element: HTMLElement, condition: (element: HTMLElement) => boolean, position: ElementPosition): HTMLElement;
/**
* find an element in a particular position with a specific condition relative to input element
* Does a DFS for this element relative the root of the graph
* @param element The current element
* @param condition The function to check the kind of element we are looking for
* @param position The ElementPosition of the desired element relative to input element
*/
static findElementFromRootDFS(element: HTMLElement, condition: (element: HTMLElement) => boolean, position: ElementPosition): HTMLElement;
/**
* find an element in a particular position with a specific condition relative to input element
* Does a DFS for this element relative the input element
* @param element The current element
* @param condition The function to check the kind of element we are looking for
* @param position The ElementPosition of the desired element relative to input element
*/
static findChildElementDFS(element: HTMLElement, condition: (element: HTMLElement) => boolean, position: ElementPosition): HTMLElement;
/**
* gets a element from a list of elements in the position relative to the current element
* @param elements the list of elements
* @param currentElement the current element
* @param position the ElementPosition we want relative to the current element
*/
static getElement(elements: HTMLElement[], currentElement: HTMLElement, position: ElementPosition): HTMLElement;
static getAllElements(element: HTMLElement, condition: (element: HTMLElement) => boolean): HTMLElement[];
/**
* gets the first element that meets a condition
* @param rootElement the element we start with
* @param condition the condition we want to find an element meeting
* @param stopLookingCondition a condition used to stop looking down a certain path
* (ie stop looking down a particular path once we hit a zone)
* @param includeRootElement a condition to include the root element in the search
*/
static getFirstElement(rootElement: HTMLElement, condition: (element: HTMLElement) => boolean, stopLookingCondition?: (element: HTMLElement) => boolean, includeRootElement?: boolean): HTMLElement;
/**
* finds all elements starting at the input element that meet the given condition
* @param rootElement the element from which to start the depth first search
* @param condition the function that determines whether the desired condition has been met
* @param stopLookingCondition a condition used to stop looking down a certain path
* @param includeRootElement a condition to include the root element in the search
*/
private static searchAllElements;
/**
* returns the root of the DOM graph
*/
static getRootElement(): HTMLElement;
/**
* Finds the next zone
* @param element the current zone or an element in the current zone
*/
static getNextZone(element: HTMLElement): HTMLElement;
/**
* gets the first focusable element in the next zone
* if a zone has no focusable elements, it is skipped
* @param element the current element
*/
static getNextZoneElement(element: HTMLElement): HTMLElement;
/**
* Finds the previous zone
* @param element the current zone or an element in the current zone
*/
static getPreviousZone(element: HTMLElement): HTMLElement;
/**
* gets the first focusable element in the previous zone
* if a zone has no focusable elements, it is skipped
* @param element the current element
* @param originalElement the element from which we begin the search. Set automatically if unset by user
*/
static getPreviousZoneElement(element: HTMLElement, originalElement?: HTMLElement): HTMLElement;
/**
* gets the first ancestor that is disabled
* @param element the element
*/
static getAncestor(element: HTMLElement, condition: MsftSme.Func1<HTMLElement, boolean>): HTMLElement;
private static getParentIframe;
/**
* gets all ancestors that match a given condition
* @param element the element
*/
static getAllAncestors(element: HTMLElement, condition: MsftSme.Func1<HTMLElement, boolean>): HTMLElement[];
/**
* gets the zone that the current element is in
* @param element the element
*/
static getAncestorZone(element: HTMLElement): HTMLElement;
/**
* determine if an element is in a trap, if so return the trap element
* @param element HTML element to check
*/
static getAncestorTrap(element: HTMLElement): HTMLElement;
/**
* gets the ancestor form of an element
* @param element the element
*/
static getAncestorForm(element: HTMLElement): HTMLElement;
/**
* Find ancestors that are disabled, hidden, or not displayed
* @param element the element
*/
static getDisabledHiddenOrNotDisplayedAncestor(element: HTMLElement): HTMLElement;
/**
* gets the first ancestor that is disabled
* @param element the element
*/
static getDisabledAncestor(element: HTMLElement): HTMLElement;
/**
* returns ancestor table of current element
* @param element the current element
*/
static getAncestorTable(element: HTMLElement): HTMLElement;
/**
* gets the next child zone of the current zone
* @param element the current zone or an element in the current zone
*/
static getDescendentZone(element: HTMLElement): HTMLElement;
/**
* gets the first focusable descendent of the current element
* @param element the current element
*/
static getFirstFocusableDescendent(element: HTMLElement): HTMLElement;
/**
* gets the last element in a zone
* @param element the element
*/
static getLastElementInZone(element: HTMLElement): HTMLElement;
/**
* gets the first element in a zone
* @param element the element
*/
static getFirstElementInZone(element: HTMLElement): HTMLElement;
/**
* gets the next focusable element in the current zone
* @param element the current element
*/
static getNextFocusableElement(element: HTMLElement): HTMLElement;
/**
* gets the previous focusable element in the current zone
* @param element the current element
*/
static getPreviousFocusableElement(element: HTMLElement): HTMLElement;
/**
* gets the ancestor of an element that has overflow
* @param element the current element
*/
static getOverflowAncestor(element: HTMLElement): HTMLElement;
/**
* gets the ancestor of an element that meets the specified condition
* @param element the current element
* @param condition the function that will check if element meets the desired condition
*/
static getSpecificAncestor(element: HTMLElement, condition: (element: HTMLElement) => boolean): HTMLElement;
/**
* gets the next focusable element in the current trap
* @param element the current element
*/
static getNextFocusableElementInTrap(element: HTMLElement): HTMLElement;
/**
* gets the previous focusable element in the current trap
* @param element the current element
*/
static getPreviousFocusableElementInTrap(element: HTMLElement): HTMLElement;
/**
* true if given element is a body element
* @param element the element
*/
static isBody(element: HTMLElement): boolean;
/**
* true if the given element is a zone
* @param element the element
*/
static isZone(element: HTMLElement): boolean;
/**
* true if the element is a focusable element that is not a zone
* @param element the element
*/
static isFocusableNonZone(element: HTMLElement): boolean;
/**
* true if the element is an input, select, or textarea without a form parent
* @param element the element
*/
static isInputWithoutForm(element: HTMLElement): boolean;
/**
* true if the element has a role that qualifies as a zone
* @param element the element
*/
static hasZoneRole(element: HTMLElement): boolean;
/**
* true if the element has class="sme-focus-zone"
* @param element the element
*/
static isSmeFocusZone(element: HTMLElement): boolean;
/**
* true if the element has a tag that is a zone
* @param element the element
*/
static hasZoneTag(element: HTMLElement): boolean;
/**
* true if element has role 'tablist'
* @param element the html element
*/
static isTablist(element: HTMLElement): boolean;
/**
* Returns true if element is active
* An element is active if it aria-selected attribute is set as true or has active or sme-active classes
* @param element the html element
*/
static isActiveOrSelected(element: HTMLHtmlElement): boolean;
/**
* Returns first active or selected descendant or null if none is found
* @param element the html element
*/
static getFirstActiveOrSelectedDescendant(element: HTMLElement): HTMLElement | null;
/**
* true if the element is a growl with a child
* @param element the element
*/
static isGrowlWithChild(element: HTMLElement): boolean;
/**
* true if element is focusable element within a form
* @param element the element
*/
static isFocusableFormElement(element: HTMLElement): boolean;
/**
* true is element is within a zone that is within a form
* @param element the element
*/
static isInZoneWithinForm(element: HTMLElement): boolean;
/**
* true is element is within a trap that is within a form
* @param element the element
*/
static isInTrapWithinForm(element: HTMLElement): boolean;
/**
* true if the given element is a trap
* @param element the element
*/
static isTrap(element: HTMLElement): boolean;
/**
* return true if element is a form
* @param element the element
*/
static isForm(element: HTMLElement): boolean;
/**
* return true if we are inside a search box that has its own arrow key controls
* @param element the element
* @param isRightArrow the right arrow was clicked
*/
static useArrowKeysWithinSearchbox(element: HTMLElement, isRightArrow: boolean): boolean;
/**
* true if given element is a search box
* @param element the element
*/
static isSearchBox(element: HTMLElement): boolean;
/**
* true if given element is a textbox in a combobox
* @param element the element
*/
static isTextBoxInComboBox(element: HTMLElement): boolean;
/**
* returns the next row in the current table
* @param element the current element
*/
static getNextRowInTable(element: HTMLElement): HTMLElement;
/**
* returns the previous row in the current table
* @param element the current element
*/
static getPreviousRowInTable(element: HTMLElement): HTMLElement;
/**
* returns true if the current element is a table row
* @param element the current element
*/
static isTableRow(element: HTMLElement): boolean;
/**
* returns true if the current element is a table cell
* @param element the current element
*/
static isTableCell(element: HTMLElement): boolean;
/**
* returns true if the current element is inside a table cell
* @param element the current element
*/
static isInTableCell(element: HTMLElement): boolean;
/**
* Gets the first action bar on the screen.
* @param element The HTML element.
* @returns The first action bar on the screen.
*/
static getFirstActionBar(element: HTMLElement): HTMLElement;
/**
* Gets the next action bar on the screen.
* @param element The HTML element.
* @returns The first action bar on the screen.
*/
static getNextActionBar(element: HTMLElement): HTMLElement;
/**
* Gets a specified action bar.
* @param element The HTML element.
* @param position The position of the desired action bar.
* @returns The specified action bar, if possible.
*/
static getActionBar(element: HTMLElement, position: ElementPosition): HTMLElement;
/**
* Determines if the HTML element is inside of an action bar.
* @param element The HTML element.
* @returns True if the HTML element is in an action bar and false if not.
*/
static isInActionBar(element: HTMLElement): boolean;
/**
* Determines if the HTML element is an action bar.
* @param element The HTML element.
* @returns True if the element is an action bar and false if not.
*/
static isActionBar(element: HTMLElement): boolean;
/**
* Determines if we should treat enter as click for a certain element
* @param element The HTML element to check
*/
static shouldTreatEnterAsClick(element: HTMLElement): boolean;
/**
* Check tab list aria-selected with active status
*/
static checkActiveTab(): void;
/**
* Update tab aria-selected status
* @param element The HTML element.
* @param isActive The HTML element is active or inactive.
*/
static updateAriaSelect(currentElement: HTMLElement, isActive: boolean): void;
/**
* @param element Element whose focus origin we are trying to determine
* @returns The element to focus on
*/
static getFocusOrigin(element: HTMLElement): HTMLElement;
}
/**
* describes the position of the desired element in a list of elements
*/
export declare enum ElementPosition {
First = 0,
Previous = 1,
Next = 2,
Last = 3
}