nrkno / core-components

Accessible and lightweight Javascript components
https://static.nrk.no/core-components/latest/
MIT License
117 stars 10 forks source link

core-toggle is positioned outside viewport on mobile #648

Closed johannesodland closed 2 years ago

johannesodland commented 2 years ago

When using autopositon on core-toggle the component checks if there is enough room for the element if it starts at the left side of the button. If not, it defaults to hanging from the right side of the button. https://github.com/nrkno/core-components/blob/4e035069e2329143bc694a3c828099b4550de2a9/packages/core-toggle/core-toggle.js#L75

On mobile, this will often cause the element to be positioned with a negative value in the left property.

This could be solved by limiting the left and right values to 0 and window.innerWidth.

As an addition it would be nice if the component supported a positioning scheme where the element is positioned directly below the button, and not hanging to the left or right.