ember-bootstrap-power-select icon indicating copy to clipboard operation
ember-bootstrap-power-select copied to clipboard

Dropdown doesn't render when used inside a modal

Open mwisner opened this issue 7 years ago • 15 comments

Hello,

I'm attempting to use the power-select control type in a simple form within a modal:

{{#bs-modal open=createInviteModalEnabled
            onSubmit=(action "inviteNewUsersSubmit")
            onHidden=(action "closeInviteModal") as |modal|}}
  {{#modal.header}}
    <h4 class="modal-title">{{fa-icon "users"}} Invite New User</h4>
  {{/modal.header}}

  {{#modal.body}}
    {{#bs-form onSubmit=(action "inviteNewUsersSubmit") model=newInvite as |form|}}
      {{form.element controlType="text" label="Name" placeholder="Bob Smith" property="metadata.name"}}

      {{#form.element controlType="power-select" label="Role" property="metadata.organization_role"  options=organizationRoles as |el|}}
        {{el.control searchEnabled=false}}
      {{/form.element}}

      {{form.element controlType="email" label="Email" placeholder="[email protected]" property="email"}}
    {{/bs-form}}
  {{/modal.body}}

  {{#modal.footer as |footer|}}
    {{#bs-button onClick=(action modal.close) type="danger"}}Cancel{{/bs-button}}
    {{#bs-button onClick=(action modal.submit) type="success"}}Invite User{{/bs-button}}
  {{/modal.footer}}

{{/bs-modal}}

I receive no errors in the console, but i'm also not seeing any options in the dropdown: screenshot 2017-08-28 20 35 16

However, if I just copy and past the same form outside of the modal:

{{#bs-form onSubmit=(action "inviteNewUsersSubmit") model=newInvite as |form|}}
  {{form.element controlType="text" label="Name" placeholder="Bob Smith" property="metadata.name"}}

  {{#form.element controlType="power-select" label="Role" property="metadata.organization_role"  options=organizationRoles as |el|}}
    {{el.control searchEnabled=false}}
  {{/form.element}}

  {{form.element controlType="email" label="Email" placeholder="[email protected]" property="email"}}
{{/bs-form}}

The dropdown seems to appear just fine: screenshot 2017-08-28 20 40 30

mwisner avatar Aug 29 '17 00:08 mwisner

Hm, both (modals and power-select menus) use ember-wormhole to add their elements to DOM, but using different wormhole-containers. Probably the power-select menu is hidden, because the modal is in front. Needs to be fixed for sure...

simonihmig avatar Sep 05 '17 09:09 simonihmig

I did a little digging and that's exactly what it is... Adding a high z-index to the wormhole for power-select fixes the issue.

mwisner avatar Sep 06 '17 18:09 mwisner

@mwisner thanks for confirming. Will keep this issue open for a built-in fix...

simonihmig avatar Sep 06 '17 20:09 simonihmig

Hi @mwisner, there is another, more convenient way, by adding power-select's renderInPlace property like so:

{{#form.element controlType="power-select" as |el|}}
  {{el.control searchEnable=false renderInPlace=true}}
{{/form.element}}

Hopefully this works for you.

dajk avatar Sep 12 '17 14:09 dajk

Does the component not support passing renderInPlace at the top level? The code below doesn't seem to be working.

<Form.element
  @controlType="power-select"
  @options={{this.i18n.localeList}}
  @optionLabelPath="text"
  @renderInPlace={{true}}
/>

However, this works.

<Form.element
  @controlType="power-select"
  @options={{this.i18n.localeList}}
  @optionLabelPath="text"
  as |Element|
>
  <Element.control @renderInPlace={{true}} />
</Form.element>

I can see the code below does support passing in renderInPlace at the top level. Not sure what might be causing it to not work. Any ideas?

https://github.com/kaliber5/ember-bootstrap-power-select/blob/5eec6c5597cea6ae90d315f3ad80f1752b66f9fd/addon/templates/components/bs-form/element/control/power-select.hbs#L96

sumeetattree avatar Apr 19 '19 16:04 sumeetattree

As mentioned on Discord already, the Form.element can only pass known and supported properties down to the control component. renderInPlace is not among those. So the second example above is indeed the way to use it, passing props to the exposed control component directly.

simonihmig avatar Apr 23 '19 08:04 simonihmig

I can confirm that this is still an issue even after upgrade to Ember Power Select v3 and Ember Bootstrap v3.

Will keep this issue open for a built-in fix...

@simonihmig Do you still consider a built-in fix? I'm tending to only document that edge case and setting renderInPlace as a work-a-round.

jelhan avatar Sep 27 '19 09:09 jelhan

This is not a bug and not about renderInPlace. This is because the modals z-index and the options are the same. The solution is to set a dropdownClass for the power select like this:

<form.element @controlType="power-select" .... as |el|>
   <el.control @dropdownClass="in-modal" />
</form.element>
.in-modal {
  z-index: 9000;
}

ohcibi avatar Mar 10 '20 15:03 ohcibi

Thanks for looking into this one @ohcibi.

Wondering why both are using the same z-index:

  • For Ember Bootstrap's modal it's the .modal class of Bootstrap that has z-index: 1050. We might not want to touch this as it's a default Bootstrap class.
  • For Ember Power Select the .ember-basic-dropdown-content class has a z-index: 1000.

We might be able to change the one of Ember Power Select to be slightly higher as the one used by an Ember Bootstrap modal. This would be an easy fix for everyone.

The value is controlled by SCSS variable $ember-basic-dropdown-content-z-index, which defaults to 1000.

Overriding it from Ember Power Select might cause issues as this would leak to other consumers of Basic Dropdown. Maybe we should propose the change upstream and see if it gets accepted. If not we can still invoke Ember Power Select with a custom class to control it's z-index at least if used through ember-bootstrap-power-select.

jelhan avatar Mar 10 '20 16:03 jelhan

The z-Index issue with bootstrap is a known one for power select. Our solution involves bootstraps sass variables. We set the z-index to $zindex-tooltip which is above modals. I wouldn’t adress this in this addon as this is beyond scope. I would just add that to the readme and link to the power select troubleshooting page for further reading.

ohcibi avatar Mar 10 '20 16:03 ohcibi

Boostrap also have a $zindex-modal variable

oliverlj avatar Jul 06 '20 08:07 oliverlj

Maybe it is worth then to add something like z-index: $zindex-modal + 10 as a sane default. Must have overlooked that var. Thanks for pointing out.

ohcibi avatar Oct 21 '20 08:10 ohcibi

@ohcibi Also thought about it. But how would you do so? Currently this addon does not provide any SCSS. Should we create a small wrapper around Ember Power Select's Bootstrap theme and ask people to use that one instead?

- @import 'ember-power-select/themes/bootstrap';
+ @import 'ember-bootstrap-power-select';
@import 'ember-power-select';

Or should we patch the ember-power-select/themes/bootstrap.scss? Technically speaking we would be able to do so. But overwriting a file provided by another addon might be considered a bad practice.

jelhan avatar Nov 25 '20 13:11 jelhan

I'd always provide scss for importing only needed styles. Shipping an entire bootstrap css can interfere with all sorts of stuff. I'm thinking of something like opting out from auto loading bootstrap and let the developer explicitly import only necessary styles.

ohcibi avatar Nov 25 '20 14:11 ohcibi

I'd always provide scss for importing only needed styles. Shipping an entire bootstrap css can interfere with all sorts of stuff. I'm thinking of something like opting out from auto loading bootstrap and let the developer explicitly import only necessary styles.

I can't follow. This addon does not ship any styles so far.

jelhan avatar Nov 25 '20 14:11 jelhan