Skip to content

Select2 with Bootstrap modal reopen issue #6391

Description

@jakubplus

The default behavior for select2 is to block vertical scroll which is fine. With 4.1.0-rc.0 although there is an issue when you re-open modal with select2 closed the vertical scroll is still blocked.

The dropdownParent property on jQuery selector is correctly set to the nearest .modal-content selector but the only way I found to overcome this is to set the scroll block off when in a modal like this:

target.on('select2:open', function (e) {
        if (!jQuery(e.target).closest('.modal').length) {
            return;
        }
        const evt = 'scroll.select2';
        jQuery(e.target).parents().off(evt);
        jQuery(window).off(evt);
    });

The issue with this solution is that it works for all modal behavior, not just the close event.

Does anyone has a more solid fix for this? Not a workaround?

jQuery v3.6.0
Bootstrap v5.3.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions