-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add option for whether to dismiss a footnote when touching outside it
This option is especially useful if the footnote is expanded inline instead of in a popover because then it doesn't make sense to hide it when clicking another place in the document.
- Loading branch information
Showing
4 changed files
with
69 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import { test, expect } from 'vitest' | ||
import { fireEvent } from '@testing-library/dom' | ||
import { | ||
setDocumentBody, | ||
getPopover, | ||
waitToStopChanging, | ||
getAllActiveButtons, | ||
getButton, | ||
} from '../helper' | ||
import littlefoot from '../../src/littlefoot' | ||
|
||
test('do not dismiss footnote when clicking the document body', async () => { | ||
setDocumentBody('single.html') | ||
littlefoot({ dismissOnDocumentTouch: false, activateDelay: 0, dismissDelay: 0 }) | ||
|
||
const button = getButton('1') | ||
fireEvent.click(button) | ||
await waitToStopChanging(button) | ||
const popover = getPopover('1') | ||
|
||
fireEvent.click(document.body) | ||
|
||
expect(popover).toBeInTheDocument() | ||
expect(button).toHaveClass('is-active') | ||
}) | ||
|
||
test('dismiss footnote when clicking the button again', async () => { | ||
setDocumentBody('single.html') | ||
littlefoot({ dismissOnDocumentTouch: false, activateDelay: 0, dismissDelay: 0 }) | ||
const button = getButton('1') | ||
fireEvent.click(button) | ||
await waitToStopChanging(button) | ||
|
||
fireEvent.click(button) | ||
|
||
expect(button).toHaveClass('is-changing') | ||
await waitToStopChanging(button) | ||
const popover = getPopover('1') | ||
expect(popover).not.toBeInTheDocument() | ||
expect(button).not.toHaveClass('is-active') | ||
}) | ||
|
||
test('disallow multiple activations', async () => { | ||
setDocumentBody('default.html') | ||
littlefoot({ dismissOnDocumentTouch: false, activateDelay: 0, dismissDelay: 0 }) | ||
|
||
const one = getButton('1') | ||
fireEvent.click(one) | ||
await waitToStopChanging(one) | ||
|
||
const two = getButton('2') | ||
fireEvent.click(two) | ||
await waitToStopChanging(two) | ||
|
||
expect(getAllActiveButtons()).toEqual([two]) | ||
}) |