Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 243
fix: click on shadowDOM popup should not close it#480
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Uh oh!
There was an error while loading. Please reload this page.
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
539bb11
fix: click on shadowDOM popup should not close it
iahu 1a764b1
feat: test click action on shadowDOM popup
iahu 271112e
Update index.tsx
iahu 9f887ad
Create global.d.ts
afc163 fb4ff21
Apply suggestions from code review
afc163 5c9994c
Update global.d.ts
afc163 9a1cf77
Update tests/shadow.test.tsx
afc163 9ba15b2
Update tests/shadow.test.tsx
afc163 b06750f
Update tests/shadow.test.tsx
afc163 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,9 @@ | ||
| // global.d.ts | ||
| declare namespace JSX { | ||
| interface IntrinsicElements { | ||
| 'custom-element': React.DetailedHTMLProps< | ||
| React.HTMLAttributes<HTMLElement> & { class?: string }, | ||
| HTMLElement | ||
| >; | ||
| } | ||
| } |
This file contains hidden or 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 hidden or 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 |
|---|---|---|
| @@ -198,3 +198,122 @@ describe('Trigger.Shadow', () => { | ||
| errSpy.mockRestore(); | ||
| }); | ||
| }); | ||
| describe('Popup.Shadow', () => { | ||
| beforeEach(() => { | ||
| resetWarned(); | ||
| jest.useFakeTimers(); | ||
| }); | ||
| afterEach(() => { | ||
| jest.useRealTimers(); | ||
| }); | ||
| class CustomElement extends HTMLElement { | ||
| disconnectedCallback() {} | ||
| connectedCallback() { | ||
| const shadowRoot = this.attachShadow({ | ||
| mode: 'open', | ||
| }); | ||
| const container = document.createElement('div'); | ||
| shadowRoot.appendChild(container); | ||
| container.classList.add('shadow-container'); | ||
| container.innerHTML = `<div class="shadow-content">Hello World</div>`; | ||
| } | ||
| } | ||
| customElements.define('custom-element', CustomElement); | ||
| it('should not close the popup when click the shadow content in the popup element', async () => { | ||
| const container = document.createElement('div'); | ||
| document.body.appendChild(container); | ||
| act(() => { | ||
| createRoot(container).render( | ||
| <> | ||
| <div className="outer">outer</div> | ||
| <Trigger | ||
| action={['click']} | ||
| autoDestroy | ||
| popup={<custom-element class="popup" />} | ||
| > | ||
| <p className="target" /> | ||
| </Trigger> | ||
| </>, | ||
| ); | ||
| }); | ||
| await awaitFakeTimer(); | ||
| // Click to show | ||
| fireEvent.click(document.querySelector('.target')); | ||
| await awaitFakeTimer(); | ||
| expect(document.querySelector('.popup')).toBeTruthy(); | ||
| // Click outside to hide | ||
| fireEvent.mouseDown(document.querySelector('.outer')); | ||
| await awaitFakeTimer(); | ||
| expect(document.querySelector('.popup')).toBeFalsy(); | ||
| // Click to show again | ||
| fireEvent.click(document.querySelector('.target')); | ||
| await awaitFakeTimer(); | ||
| expect(document.querySelector('.popup')).toBeTruthy(); | ||
| // Click on popup element should not hide | ||
| fireEvent.mouseDown(document.querySelector('.popup')); | ||
| await awaitFakeTimer(); | ||
| expect(document.querySelector('.popup')).toBeTruthy(); | ||
| // Click on shadow content should not hide | ||
| const popup = document.querySelector('.popup'); | ||
| fireEvent.mouseDown(popup.shadowRoot.querySelector('.shadow-content')); | ||
| await awaitFakeTimer(); | ||
| expect(document.querySelector('.popup')).toBeTruthy(); | ||
| }); | ||
| it('should works with custom element trigger', async () => { | ||
| const container = document.createElement('div'); | ||
| document.body.innerHTML = ''; | ||
| document.body.appendChild(container); | ||
| act(() => { | ||
| createRoot(container).render( | ||
| <> | ||
| <div className="outer">outer</div> | ||
| <Trigger | ||
| action={['click']} | ||
| autoDestroy | ||
| popup={<custom-element class="popup" />} | ||
afc163 marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| > | ||
| <custom-element class="target" /> | ||
afc163 marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| </Trigger> | ||
| </>, | ||
| ); | ||
| }); | ||
| await awaitFakeTimer(); | ||
| // Click to show | ||
| const target = document.querySelector('.target'); | ||
| fireEvent.click(target); | ||
| await awaitFakeTimer(); | ||
| expect(document.querySelector('.popup')).toBeTruthy(); | ||
| // Click outside to hide | ||
| fireEvent.mouseDown(document.querySelector('.outer')); | ||
| await awaitFakeTimer(); | ||
| expect(document.querySelector('.popup')).toBeFalsy(); | ||
| // Click shadow content to show | ||
| fireEvent.click(target.shadowRoot.querySelector('.shadow-content')); | ||
| await awaitFakeTimer(); | ||
| expect(document.querySelector('.popup')).toBeTruthy(); | ||
| // Click on shadow content should not hide | ||
| const popup = document.querySelector('.popup'); | ||
| fireEvent.mouseDown(popup.shadowRoot.querySelector('.shadow-content')); | ||
| await awaitFakeTimer(); | ||
| expect(document.querySelector('.popup')).toBeTruthy(); | ||
| }); | ||
| }); | ||
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.