Mirror: React hooks for accessible, common web interactions. UI super powers without the UI.

Invert priority stack

Changed files
+5 -5
src
+5 -5
src/usePriority.ts
···
const sortByHierarchy = (a: HTMLElement, b: HTMLElement) => {
const x = a.compareDocumentPosition(b);
return (
-
(x & 16 /* a contains b */ && -1) ||
-
(x & 8 /* b contains a */ && 1) ||
-
(x & 2 /* b follows a */ && -1) ||
-
(x & 4 /* a follows b */ && 1) ||
+
(x & 16 /* a contains b */ && 1) ||
+
(x & 8 /* b contains a */ && -1) ||
+
(x & 2 /* b follows a */ && 1) ||
+
(x & 4 /* a follows b */ && -1) ||
0
);
};
···
function computeHasPriority(): boolean {
if (!ref.current) return false;
const tempStack = priorityStack.concat(ref.current).sort(sortByHierarchy);
-
return tempStack[tempStack.length - 1] === ref.current;
+
return tempStack[0] === ref.current;
}
const isDisabled = !!disabled;