Bugfix/multiple selectors modal doesnt close#201
Open
Tazovsky wants to merge 3 commits intothomasp85:mainfrom
Open
Bugfix/multiple selectors modal doesnt close#201Tazovsky wants to merge 3 commits intothomasp85:mainfrom
Tazovsky wants to merge 3 commits intothomasp85:mainfrom
Conversation
This commit fixes the issue where modals don't close after clicking 'Select' when using multiple shinyDirChoose buttons with different IDs in R Shiny apps. Root Cause: - Each shinyDirChoose button creates its own modal with unique ID - JavaScript event handlers used generic selectors (.sF-modalContainer) that could match multiple modals - When multiple modals exist, event handlers may target wrong modal or cause conflicts - No cleanup of existing modals when creating new ones Changes Made: 1. Added modal cleanup on creation: - Added cleanup code in createFileChooser(), createDirChooser(), createFileSaver() - Removes existing modals for same button before creating new one - Ensures each button only has one active modal at a time 2. Fixed keydown handler: - Changed from generic selector to finding currently visible modal - Uses .sF-modalContainer:visible.first() instead of .sF-modalContainer - Prevents conflicts between multiple modals 3. Fixed backdrop click handler: - Updated to work with specific modal that was clicked - Uses .find() instead of global selectors - Ensures correct modal is closed when clicking backdrop 4. Fixed escape key handler: - Updated to work with currently visible modal - Uses visibleModal.find() instead of global selectors - Ensures escape key closes correct modal Impact: - Resolves modal not closing issue with multiple shinyDirChoose buttons - Backward compatible - doesn't affect single modal usage - Improves reliability when using multiple file/directory choosers
Added Kamil Foltynski to the Authors@R field in DESCRIPTION with role 'ctb' (contributor) to recognize the contribution to fixing the multiple modal issue in shinyDirChoose functionality.
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.