reka-ui
Version:
Vue port for Radix UI Primitives.
22 lines (20 loc) • 904 B
text/typescript
export function excludeTouch(eventHandler: () => void) {
return (event: PointerEvent) => event.pointerType === 'touch' ? undefined : eventHandler()
}
/**
* Returns a list of nodes that can be in the tab sequence.
* @see: https://developer.mozilla.org/en-US/docs/Web/API/TreeWalker
*/
export function getTabbableNodes(container: HTMLElement) {
const nodes: HTMLElement[] = []
const walker = document.createTreeWalker(container, NodeFilter.SHOW_ELEMENT, {
acceptNode: (node: any) => {
// `.tabIndex` is not the same as the `tabindex` attribute. It works on the
// runtime's understanding of tabbability, so this automatically accounts
// for any kind of element that could be tabbed to.
return node.tabIndex >= 0 ? NodeFilter.FILTER_ACCEPT : NodeFilter.FILTER_SKIP
},
})
while (walker.nextNode()) nodes.push(walker.currentNode as HTMLElement)
return nodes
}