Bugfix/multiple selectors modal doesnt close #201
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.
Fix for Multiple shinyDirChoose Modal Issue
Problem Description
When using multiple
shinyDirChoosebuttons with different IDs in an R Shiny app, the modal where directories are selected does not close after clicking "Select". This issue occurs because:shinyDirChoosebutton creates its own modal with a unique ID.sF-modalContainer) that can match multiple modalsRoot Cause
The issue was in the JavaScript code in
inst/www/shinyFiles.js:Solution
The fix includes several changes to
inst/www/shinyFiles.js:1. Modal Cleanup on Creation
Added cleanup of existing modals when creating new ones in all three modal creation functions:
This ensures that each button only has one active modal at a time.
2. Fixed Keydown Handler
Changed the keydown handler to work with multiple modals by finding the currently visible modal:
3. Fixed Backdrop Click Handler
Updated the backdrop click handler to work with the specific modal that was clicked:
4. Fixed Escape Key Handler
Updated the escape key handler to work with the currently visible modal:
Testing
Files Modified
inst/www/shinyFiles.js: Fixed modal creation and event handlersImpact
This fix resolves the issue where modals don't close after clicking "Select" when using multiple
shinyDirChoosebuttons. The fix is backward compatible and doesn't affect single modal usage.