-
Notifications
You must be signed in to change notification settings - Fork 249
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: support CSS pointer-events property (#631)
Co-authored-by: Philipp Fritsche <[email protected]>
- Loading branch information
1 parent
f633a52
commit 32e9712
Showing
12 changed files
with
166 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import {hasPointerEvents} from 'utils' | ||
import {setup} from '__tests__/helpers/utils' | ||
|
||
test('get pointer-events from element or ancestor', () => { | ||
const {element} = setup(` | ||
<div style="pointer-events: none"> | ||
<input style="pointer-events: initial"/> | ||
<input style="pointer-events: inherit"/> | ||
<input/> | ||
</div> | ||
`) | ||
|
||
expect(hasPointerEvents(element as HTMLDivElement)).toBe(false) | ||
expect(hasPointerEvents((element as HTMLDivElement).children[0])).toBe(true) | ||
expect(hasPointerEvents((element as HTMLDivElement).children[1])).toBe(false) | ||
expect(hasPointerEvents((element as HTMLDivElement).children[2])).toBe(false) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import {getWindowFromNode} from '@testing-library/dom/dist/helpers' | ||
|
||
export function hasPointerEvents(element: Element): boolean { | ||
const window = getWindowFromNode(element) | ||
|
||
for ( | ||
let el: Element | null = element; | ||
el?.ownerDocument; | ||
el = el.parentElement | ||
) { | ||
const pointerEvents = window.getComputedStyle(el).pointerEvents | ||
if (pointerEvents && !['inherit', 'unset'].includes(pointerEvents)) { | ||
return pointerEvents !== 'none' | ||
} | ||
} | ||
|
||
return true | ||
} |