Skip to content

Numerous fixes (#312, #338, etc.) + new features!#545

Open
mike-vel wants to merge 1 commit intomicromodal:masterfrom
mike-vel:public
Open

Numerous fixes (#312, #338, etc.) + new features!#545
mike-vel wants to merge 1 commit intomicromodal:masterfrom
mike-vel:public

Conversation

@mike-vel
Copy link
Copy Markdown

Here is a pull request that aims to fix multiple issues and add new features:

The code here is from https://github.com/mike-vel/Micromodal-test

Issues fixed:

  1. Closing modals programmatically causes issues when multiple modals are present on a single page #338: The library here now stores allModals and activeModals for the library to access the functions.
  2. onClose not called when provided to Micromodal.init #354:
    • The options provided by the MicroModal.init are now stored globally in the module, related to fixes #187 #539
    • MicroModal.show now calls allModals[targetId].showModal() instead of initializing a new Modal
  3. Destroying instances #312: The library now provides MicroModal.removeModal, which unregisters a modal and removes its event listeners and triggers
  4. When launching 2nd modal from modal, escape key closes both modals #421 and Bug: Tabbing and focus trapping doesn't work properly when multiple modals are open #544: The keydown listeners are now assigned to each modal instead.
  5. Breaking change in 0.4.9: clicking the container closes the modal #490: The library now uses a more sophisticated condition on whether or not clicking somewhere with a data-micromodal-close attribute closes a modal.
    + more that I probably didn't mention here

New features:

  • MicroModal.closeAll(): Closes all active modals
  • MicroModal.config(targetModal, config): Configures the settings of a specific modal
  • MicroModal.initModal: Initializes a new unregistered modal
  • MicroModal.removeModal: Removes the modals from the allModals list. Hides the modal and removes all event listeners and triggers before removing
  • Putting role="alertdialog" now disables the Esc key. (Using this indicates an urgent response from the user)

Things to do:

  • Revamp the documentation
  • Add missing features in docs
  • Fix more issues

Note

The new pull request is similar to #543 and is there to prevent clutter.

* fix: MicroModal.close causing issues

It now tracks all modals and active modals instead of one active modal.

Fixes micromodal#338
BREAKING CHANGE: Modals now must have ids to function properly.

* feat: add MicroModal.config

- Initial options are now stored globally
- MicroModal.config modifies the configurations of a modal
- Big fix: config option does not apply in MicroModal.show

* add: initModal and removeModal

- Modals are now tracked by modalId (can be modified by setting the
  identifier in MicroModal.init)
- Added initModal: initializes a modal, used for dynamic content
- Added removeModal: removes a modal from the allModals list

Could Fix micromodal#312

* chore: improve debugMode

- Fixes some bugs in debugMode
- Improves the debugMode warnings
- MicroModal.show now initializes a new modal if it is unregistered

* fix: micromodal#421, micromodal#544, and micromodal#372

- Fixes issues micromodal#421, micromodal#544, micromodal#372, and micromodal#523.
- Fixes a bug:
    When removing a modal with animation, showing it again causes the
    modal to animate then disappear.

* docs: add new features

- Adds new features in documentation
- Fixes some bugs related to highlighting

* Update README.md

Adds testing version

* refactor: separated functions in index,js

Refactors some code as well as:
- Fixes some behavior when scrolling is disabled
- Adds an exported public API

* add: support on html elements in functions

* refactor: making the code readable

* refactor: making the code readable

- Adds new comments for easier readability
- Improves existing code

* add: nanomodal.js

- Adds a smaller version of mocromodal.js

* fix: focus trap from outside doesn't work

Fixes a bug where, if the focus is outside the modal, it does not immediately
enter the modal when the user presses the Tab key.
This is due to the keydown handler only affecting inside the modal.

* Update README.md

* fix: micromodal#105, micromodal#490

- Fixes issues micromodal#105, micromodal#490
- Fixes StandardJS errors

* add: safeguards to prevent errors

- Fixes role="alertdialog" not disabling Escape key presses
- Added some safeguards

* add(nanomodal): missing features

* refactor: remove unnecessary code
@mike-vel mike-vel changed the title Improved micromodal.js (#2) Numerous fixes (#312, #338, etc.) + new features! Sep 26, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant