-
-
Notifications
You must be signed in to change notification settings - Fork 142
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' of github.com:excid3/tailwindcss-stimulus-components
- Loading branch information
Showing
10 changed files
with
69 additions
and
38 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
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 @@ | ||
<div class="my-12"> | ||
<h2 class="text-2xl text-gray-800 font-semibold mb-4">Modals</h2> | ||
<p>Modals use the <code><dialog></code> html element and can be closed with <kbd>Esc</kbd> or a button. See the | ||
<a href="https://developer.mozilla.org/en-US/docs/Web/HTML/Element/dialog#accessibility_concerns" target="_blank" | ||
class="underline text-blue-500">dialog element MDN docs</a>. | ||
</p> | ||
|
||
<div data-controller="modal"> | ||
<dialog data-modal-target="dialog" class="p-8 rounded-lg backdrop:bg-black/80"> | ||
<p>This modal dialog has a groovy backdrop!</p> | ||
<button autofocus data-action="modal#close" | ||
class="px-2.5 py-1 bg-blue-500 text-white text-sm rounded">Close</button> | ||
</dialog> | ||
<button data-action="modal#open" | ||
class="bg-blue-500 hover:bg-blue-700 text-white text-sm font-bold py-1 px-2.5 rounded">Open modal</button> | ||
</div> | ||
</div> |
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,41 @@ | ||
import { fixture, expect } from '@open-wc/testing' | ||
import { sendKeys } from '@web/test-runner-commands'; | ||
import { fetchFixture } from './test_helpers' | ||
|
||
import { Application } from '@hotwired/stimulus' | ||
import Modal from '../src/modal' | ||
|
||
describe('ModalController', () => { | ||
describe('#default', () => { | ||
beforeEach(async () => { | ||
const html = await fetchFixture('modal.html') | ||
await fixture(html) | ||
const application = Application.start() | ||
application.register('modal', Modal) | ||
}) | ||
|
||
const openModalButton = document.querySelector("[data-action='modal#open']") | ||
|
||
it('clicks to open and close the modal', async () => { | ||
const dialog = document.querySelector("dialog") | ||
const openModalButton = document.querySelector("[data-action='modal#open']") | ||
openModalButton.click() | ||
expect(dialog.hasAttribute("open")).to.equal(true) | ||
|
||
const closeModalButton = document.querySelector("[data-action='modal#close']") | ||
closeModalButton.click() | ||
expect(dialog.hasAttribute("open")).to.equal(false) | ||
}) | ||
|
||
it('uses the keyboard to open and close the modal', async () => { | ||
const dialog = document.querySelector("dialog") | ||
const openModalButton = document.querySelector("[data-action='modal#open']") | ||
openModalButton.focus() | ||
await sendKeys({ press: 'Space' }); | ||
expect(dialog.hasAttribute("open")).to.equal(true) | ||
|
||
await sendKeys({ press: 'Escape' }); | ||
expect(dialog.hasAttribute("open")).to.equal(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