Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Vue multiselect inside of element with scrollbar #723

Closed
MattCCC opened this issue May 10, 2018 · 12 comments
Closed

Vue multiselect inside of element with scrollbar #723

MattCCC opened this issue May 10, 2018 · 12 comments

Comments

@MattCCC
Copy link

MattCCC commented May 10, 2018

Hi, firstly thank you for a great plugin, it's really great.

I found one issue with using vue vue-multiselect inside of elements with overflow:auto. After to expand, vue multiselect is still inside of the element with overflow auto, which is not how the standard <select> works.

Fiddle: https://jsfiddle.net/jqofkzxc/3078/

Expected behaviour: After to expand the vue-multiselect (.multiselect__content-wrapper) shouldn't cause the .modal-body to expand.

Possible fix: This could be achieved by setting it outside of element with overflow (.modal-body in that case), and using position absolute + dynamically counted left/top css.

Why? It would make it much easier to use it in replacement to standard without any hacks.

@shentao
Copy link
Owner

shentao commented May 19, 2018

Yeah, that’s an issue related to the current structure of the code – the dropdown is located just next to the input, thus it is also affected by all the overflows of the code around it.

I think you can try to fix this with some combination of position absolute and static. Here’s a nice article about that: https://css-tricks.com/popping-hidden-overflow/

@stale
Copy link

stale bot commented Jul 22, 2018

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the wontfix label Jul 22, 2018
@stale stale bot closed this as completed Jul 29, 2018
@me-singh
Copy link

Is there any way we can overcome this issue. I want dropdown to appear above overflow (it is blocked by overflow).

@sigma207
Copy link

@me-singh
You can try this directive.

@Kocal
Copy link

Kocal commented Jul 17, 2020

I've used @sigma207 directive, but unfortunately I've got two issues with it:

  • when scrolling, the multiselect does not move and that's weird
  • the parent element lose its height since the multiselect is in position: fixed, so next elements are moved up and this is not wanted

I've patched it to use position: absolute instead of fixed, and used an invisible clone to preserve the parent height:

export default {
  install(Vue) {
    Vue.directive('select-overflow', {
      inserted: (el, _binding, vnode) => {
        let originalWidth
        let originalPosition
        let originalZIndex
        let selectIsOpen = false
  
        // will be used as a placeholder, in order to fix parent height issue (due to position relative)
        const clone = el.cloneNode(true);
        clone.style.visibility = 'hidden';

        vnode.child.$watch('isOpen', isOpen => {
          selectIsOpen = isOpen
          if (isOpen) {
            const { offsetWidth } = el
            originalWidth = el.style.width
            originalPosition = el.style.position
            originalZIndex = el.style.zIndex
            el.style.width = `${offsetWidth}px`
            el.style.position = 'absolute'
            el.style.zIndex = 2
            el.parentNode.insertBefore(clone, el.nextSibling); // insert after el
          } else {
            el.style.position = originalPosition
            el.style.width = originalWidth
            el.style.zIndex = originalZIndex
            clone.parentNode.removeChild(clone);
          }
        })

        window.addEventListener('wheel', event => {
          if (selectIsOpen) {
            // disabled outside scroll when select is open
            event.stopPropagation()
          }
        }, true)
      },
    })
  }
}

EDIT: I've encountered some issues with the vue-multiselect's position in a scrollable element, which was not displayed properly.
I'm now setting position: relative to the parent element and it's now working well:

// See https://github.com/shentao/vue-multiselect/issues/723#issuecomment-596988587
// and https://gist.github.com/sigma207/b9300fe12a996c07b2389ee03c1464ed

export const directiveOverflow = {
  inserted: (el, _binding, vnode) => {
    let originalParentPosition;
    let originalWidth;
    let originalPosition;
    let originalZIndex;
    let selectIsOpen = false;

    // will be used as a placeholder, in order to fix parent height issue (due to position relative)
    const clone = el.cloneNode(true);
    clone.style.visibility = 'hidden';

    vnode.child.$watch('isOpen', (isOpen) => {
      selectIsOpen = isOpen;

      if (isOpen) {
        const { offsetWidth } = el;
        originalParentPosition = el.parentElement.style.position;
        originalWidth = el.style.width;
        originalPosition = el.style.position;
        originalZIndex = el.style.zIndex;
        el.parentElement.style.position = 'relative';
        el.style.width = `${offsetWidth}px`;
        el.style.position = 'absolute';
        el.style.zIndex = 9999;
        el.parentNode.insertBefore(clone, el.nextSibling); // insert after el
      } else {
        el.parentElement.style.position = originalParentPosition;
        el.style.position = originalPosition;
        el.style.width = originalWidth;
        el.style.zIndex = originalZIndex;
        clone.parentNode.removeChild(clone);
      }
    });

    window.addEventListener(
      'wheel',
      (event) => {
        if (selectIsOpen) {
          // disabled outside scroll when select is open
          event.stopPropagation();
        }
      },
      true
    );
  },
};

@ryzhak-andrii
Copy link

@Kocal It work's only for the not scrollable parent with a select within. In another case, I have this result
Screen Shot 2020-07-20 at 6 30 15 PM

@Kocal
Copy link

Kocal commented Aug 6, 2020

@ryzhak-andrii I think I had the same issue than you, can you try the new snippet in #723 (comment)? I'm now setting position: relative to the vue-multiselect parent.

@ohasy
Copy link

ohasy commented Oct 10, 2020

Here, did the fix for overflow or z-index issues by appending options to body with the help of@Kocal's comment and appending the options to body.
PR

@renanreis
Copy link

This workaround worked for me:

.multiselect__content-wrapper {
position: static;
}

@atymic
Copy link

atymic commented Nov 6, 2023

Anyone got this working on vue3?

@mattelen
Copy link
Collaborator

mattelen commented Nov 6, 2023

Anyone got this working on vue3?

Trying installing the latest beta version as that supports Vue 3. If you are still having issues, please open a new issue

@atymic
Copy link

atymic commented Nov 7, 2023

Anyone got this working on vue3?

Trying installing the latest beta version as that supports Vue 3. If you are still having issues, please open a new issue

More I meant the gists, they seem to work only with vue2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

10 participants