Skip to content

Conversation

@Pytal
Copy link

@Pytal Pytal commented Feb 11, 2023

The calculated dropdown list width, passed to calculatePosition() when appendToBody is true, should be equal to the toggle width. Width is calculated before the dropdown list is appended to body and is still a child of the Select component.

If the Select component is mounted within a container that overflows and shows a scrollbar when a child dropdown list is opened, the toggle width is calculated with the scrollbar taken into account and therefore will equal the original toggle width minus the scrollbar width.

When appended to body the dropdown list does not overflow the container

Thus calculatePosition() is given a width less than the toggle width.

To fix this discrepancy we mount the dropdown list to body before the calculation instead of after.


The width is calculated when the dropdown list is still a child element of the Select component (although this happens too quickly to see) and before it is appended to body, a visual example of the DOM state when this happens, by setting :append-to-body="false" and overflow: auto on the container, can be seen below

image

Before After
image image

- The calculated dropdown list width, passed to `calculatePosition()`
  when `appendToBody` is true, should be equal to the toggle width
- Width is calculated before the dropdown list is appended to `body` and
  is still a child of the Select component
- If the Select component is mounted within a container that overflows
  and shows a scrollbar when a child dropdown list is opened, the toggle
  width is calculated with the scrollbar taken into account and
  therefore will equal the original toggle width minus the scrollbar
  width
- When appended to `body` the dropdown list does not overflow the
  container
- Thus `calculatePosition()` is given a width less than the toggle width
- To fix this discrepancy we mount the dropdown list to `body` before
  the calculation instead of after

Signed-off-by: Christopher Ng <[email protected]>
@Pytal Pytal added the type: bug 🐛 Something isn't working label Feb 11, 2023
@Pytal Pytal added this to the 3.22.1 milestone Feb 11, 2023
@Pytal Pytal self-assigned this Feb 11, 2023
@Pytal Pytal merged commit 750521e into master Feb 11, 2023
@Pytal Pytal deleted the fix/append-body-calc-width branch February 11, 2023 03:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

type: bug 🐛 Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants