3

I have some problem with table-responsive class because it is generating scroll on y axis when it is not indicated on the css.

Here is picture of the problem Text and I also replicated the bug

<div id="app">
  <div class="container">
    <div class="table-responsive">
       <table class="table table-bordered">
        <thead>
          <tr>
            <th>N°</th>
            <th>Test</th>
          </tr>
        </thead>
        <tbody>
          <tr>
            <td>1</td>
            <td>
              <multiselect 
                v-model="value" 
                :options="options"
                :multiple="true"
                track-by="library"
                :custom-label="customLabel"
                >
              </multiselect>
            </td>
          </tr>
        </tbody>
      </table>
    </div>
  </div>
</div>

https://jsfiddle.net/ggalvez92/3d8h4sqy/

I have tried to put overflow-y: visible but nothing seems to work.

I would appreciate if someone can help me to fix it.

1 Answers1

3

If we change:

.multiselect__content-wrapper { display: contents; }

It can grow inside the table cell but affecting the table height.


Or if you use:

.table-responsive { overflow: unset; }

It can grow outside of the cell without affecting the table height.


So to fix the dropdown outside the table cell and keep overflow on the .table-responsive I don't believe this can be fixed CSS only. JavaScript solutions have been reported to:

  • add some bottom padding (only applicable when the dropdowns are on the last rows)
  • append the dropdown to the body and recalculate the offset
  • add position: fixed when open, and recalculate width, left and right offset

So, after some struggle with Vue (first time) I've found a solution that might suit your needs. This solution uses the position: fixed as mentioned earlier.

repositionDropdown (id){
    const el = document.getElementById(id);
    const parent = el.closest('.multiselect');
    const content = parent.querySelector('.multiselect__content-wrapper');
    const { top, height, left } = parent.getBoundingClientRect();

    content.style.width = `${parent.clientWidth}px`;
    content.style.position = 'fixed';
    content.style.bottom = 'auto';
    content.style.top = `${top + height}px`;
    content.style.left = `${left}px`;
}

By adding the @open event to the setup it also requires an :id. For some reason this id needs to be numeric, I don't know why at this point. It might need some extra finetuning but at least it solves one of the bigger issues.

DEMO

Tim Vermaelen
  • 6,869
  • 1
  • 25
  • 39
  • The problem is that I have almost 20 columns so I cannot disabled the overflow-x – GianPierre Gálvez May 01 '20 at 02:55
  • That's what I've been solving too, did I not? Three solutions but please look at the DEMO. – Tim Vermaelen May 01 '20 at 09:43
  • Ok, after some more investigation I see your pain more clearly. Best to let it grow inside the cell as you will most likely not fix this issue with CSS only. – Tim Vermaelen May 01 '20 at 11:09
  • yes ,it seems that is the only solution with css, but do you if there is something that can be done with js to fix this problem? because I have also tried to create out div with position absolute and it is the same problem that multiselected did – GianPierre Gálvez May 01 '20 at 12:47
  • There are some javascript solution in this [github issue thread](https://github.com/twbs/bootstrap/issues/11037) but it's Bootstrap dropdown related which is also not exactly your use case. – Tim Vermaelen May 01 '20 at 12:56
  • 1
    I really appreciate your help, it works perfect with your js solution. Thanks you so much. – GianPierre Gálvez May 04 '20 at 14:49
  • My row was there with a child element emitting the event. To solve this problem, I emitted the $el as a reference, and it meant that I didn't need to set an ID. – Aaron Morefield Dec 21 '20 at 23:10