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

Is it possible to teleport the dropdown to another component? #365

Open
yukosgiti opened this issue Jul 25, 2022 · 1 comment
Open

Is it possible to teleport the dropdown to another component? #365

yukosgiti opened this issue Jul 25, 2022 · 1 comment

Comments

@yukosgiti
Copy link

When the component is rendered at the end of a container, the opening dropdown is clipped by the container. Is it possible to teleport the dropdown to another compnent to fix this issue? Something like this

<container1>
    <container2>
        <vue-tel-input teleportDropdownTo="#target"/>
    </container2>
    <div id="#target"/> //The dropdown is rendered here
</container1>
@yukosgiti yukosgiti changed the title Is it possible to teleport the dropdown to another compnent? Is it possible to teleport the dropdown to another component? Jul 25, 2022
@MiguelQueiroz
Copy link

MiguelQueiroz commented Jan 5, 2023

Yes, sadly ugly since this should be handled by the component.

I solved using this css class:

/* Fix int phone css */

ul.vti__dropdown-list {
  position: absolute;
  width: 100%;
  border-radius: 1px !important;
  outline: none;
  background-color: white;
  padding-left: 0px !important;
}

And on the vue component:

 <vue-tel-input
              ref="vue-tel-input"
              v-model="client.phone"
              @validate="validatePhone"
              @open="vueTelInputDropDownOpen($refs['vue-tel-input'].$refs)"
              mode="international"
              :dropdownOptions="{ showFlags: true, showSearchBox: true, showDialCodeInList: true }"
              :inputOptions="{ showDialCode: true, placeholder: 'Phone' }"
            >
            </vue-tel-input>

and the vue template methods:

methods: {
   vueTelInputDropDownOpen ($refs) {
  
 /* By the way, need the timeout because, the event open of the dropdown is before the ul is created, so the ul is not available, need to wait a frame, hence the timeout, to catch the right reference "$ref" to the input*/
  setTimeout(() => {
       let listElement = $refs.list
       let targetPosition=$refs.list.parentElement.closest('li') //modify as needed

       //detach and re-attach to another position.
       let detached= listElement.parentNode.removeChild(listElement);  
       targetPosition.appendChild(detached);
     })

   },

Or go full height / width CSS:

ul.vti__dropdown-list {
  position: fixed; 
  min-height: 100%;
  width: 100%;
  border-radius: 1px !important;
  outline: none;
  padding-left: 0px !important;
  z-index: 1000;
}

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

No branches or pull requests

2 participants