AlaskaAirlines / auro-accordion

Custom element that allows users to toggle the display for sections of content
https://auro.alaskaair.com/components/auro/accordion
Apache License 2.0
1 stars 2 forks source link

scrollIntoView being triggered before the height is added #31

Closed Eliza-Huang closed 3 years ago

Eliza-Huang commented 3 years ago

Describe the bug

When opening the accordion, it does not scroll such that the bottom of the screen aligns with the bottom of the drawer so that we can see the content of the drawer without manually scrolling. Right now that behavior is happening when we close the drawer but it's not useful since the drawer is already closed.

Although there is a scroll event when we open or close the accordion, the scroll event is happening before or at the same time that the height of the accordion is changed so when we open it, it only scrolls to the bottom of the trigger section.

To Reproduce

Steps to reproduce the behavior:

  1. Go to https://auro.alaskaair.com/components/auro/accordion
  2. Scroll down to an auro-accordion
  3. Position the accordion such that it's at the bottom of your screen
  4. Open the drawer, notice that the screen does not move.
  5. Close the drawer, notice that now the screen scrolls down such that the bottom of the screen aligns with where the bottom of the drawer used to be.

Expected behavior

When you open the drawer, the screen will scroll such that the whole drawer can be seen on the screen.

Screenshots

Video of the current behavior: https://user-images.githubusercontent.com/50314220/135501775-844ea3d9-2087-40d6-8daa-bafa97a02269.mp4

Desktop (please complete the following information):

Smartphone (please complete the following information):

Tested the auro-accordion on an iPhone6s with iOS 14 and there was no scroll functionality when a drawer is opened so assuming that it's not built for mobile devices.

Additional context

An easy fix would be to add a timeout to scrollIntoView like

setTimeout(() => {
    this.scrollIntoView({
      behavior: "smooth",
      block: "nearest"
    });
}, 500);

However, there may be a better solution since this scrolls after the drawer has been expanded, not while it is being expanded.