Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
firestar300 committed Oct 10, 2024
2 parents c85c2cd + 0a67730 commit e328d04
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 1 deletion.
1 change: 1 addition & 0 deletions examples/accessible-modal/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ Modal.initFromPreset();
|---------------------|-----------------|------------------|-----------------------------------------------------------------------------|
| closeButtonSelector | boolean\|string | `.modal__close` | The selector of the modal close button. |
| closedClassName | string | `modal--hidden` | The class name when the modal is hidden. |
| closeOnEscapeKey | boolean | `true` | Should the 'Escape' key close the modal? |
| closeOnFocusOutside | boolean\|string | `false` | Specify the selector in which the modal should close on click. If false, the modal does not close on outside click. If true, the modal closes on outside click of the element. |
| descriptionSelector | boolean\|string | `false` | The selector of the modal label (for the attribute ` aria-describedby ` ). |
| labelSelector | boolean\|string | `false` | The selector of the modal label (for the attribute ` aria-labelledby ` ). |
Expand Down
54 changes: 54 additions & 0 deletions examples/accessible-modal/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,55 @@ <h4 class="modal__title">Add delivery address</h4>
</div>
</div>

<h3 class="text-2xl mb-5">Disable <kbd>Escape</kbd> key</h3>

<button class="modal-btn" type="button" aria-controls="demo-5">Add billing address</button>

<div id="demo-5" class="modal modal--demo-5" tabindex="-1" role="dialog" aria-modal="true" aria-hidden="true">
<div class="modal__inner">
<h4 class="modal__title">Add delivery address</h4>

<div>
<div class="mb-4">
<label for="street">
<span>Street:</span>
<input id="street" type="text">
</label>
</div>
<div class="mb-4">
<label for="city">
<span>City:</span>
<input id="city" type="text">
</label>
</div>
<div class="mb-4">
<label for="state">
<span>State:</span>
<input id="state" type="text">
</label>
</div>
<div class="mb-4">
<label for="zip">
<span>Zip:</span>
<input id="zip" type="text">
</label>
</div>

<div>
<label for="special_instructions">
<span>Special instructions:</span>
</label>
<input id="special_instructions" type="text" aria-describedby="special_instructions_desc" class="mb-2">
<div id="special_instructions_desc">For example, gate code or other information to help the driver find you</div>
</div>
</div>

<button id="demo-2-close" type="button" class="modal__close">
<span class="sr-only">Close</span>
</button>
</div>
</div>

<h2>Code</h2>

<p class="codepen" data-height="600" data-theme-id="light" data-default-tab="html,result" data-slug-hash="mdwOVBm" data-user="beapi" style="height: 600px; box-sizing: border-box; display: flex; align-items: center; justify-content: center; border: 2px solid; margin: 1em 0; padding: 1em;">
Expand Down Expand Up @@ -249,6 +298,11 @@ <h2>Code</h2>
labelSelector: '.modal__title',
closeButtonSelector: '.modal__close',
},
'#demo-5': {
labelSelector: '.modal__title',
closeButtonSelector: '.modal__close',
closeOnEscapeKey: false,
},
}

Modal.initFromPreset()
Expand Down
1 change: 1 addition & 0 deletions examples/accessible-modal/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
}

.modal__inner {
position: relative;
width: 100%;
max-width: 600px;
padding: 30px;
Expand Down
3 changes: 2 additions & 1 deletion src/classes/Modal.js
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ function handleKeydown(e) {
this.checkNextFocusableElement(e)
break
case 'Escape':
if (this.isOpened) {
if (this.isOpened && this._settings.closeOnEscapeKey) {
this.close()
}
}
Expand Down Expand Up @@ -332,6 +332,7 @@ function handleTransitionEnd() {
Modal.defaults = {
closeButtonSelector: '.modal__close',
closedClassName: 'modal--hidden',
closeOnEscapeKey: true,
closeOnFocusOutside: false,
descriptionSelector: false,
labelSelector: false,
Expand Down

0 comments on commit e328d04

Please sign in to comment.