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

[Bug][Cell]: в draggable режиме не работает автоскролл если у родителя нет height: 100% #6338

Closed
inomdzhon opened this issue Dec 25, 2023 · 3 comments · Fixed by #6456 or #6461

Comments

@inomdzhon
Copy link
Contributor

inomdzhon commented Dec 25, 2023

Описание

Если нет повсеместного height: 100%, начинаю с html и body, то в <Cell draggable /> не работает автоскролл при перетаскивании к низу области видимости.

Видео с воспроизведением

before.mov

Нюанс

Если расставить height: 100%, то автоскролл починиться, но это решение подходит для всех приложений. На видео ниже пример, где height: 100% ломает страницу.

Видео c воспроизведением, где расставленн `height: 100%`

after.mov

Версия

= 5.10.0

В каких браузерах воспроизводится проблема?

No response

Шаги воспроизведения

  1. Использовать <App mode="partial" />.
  2. Создать список элементов из <Cell draggable />, чтобы на странице появился скролл.
  3. Попробовать перетащить один из элементов <Cell draggable /> к нижнему краю области видимости
  4. ❌ Страница не автоскролится вниз.

Ожидаемое поведение

Страница автоскролится вниз.

@inomdzhon inomdzhon self-assigned this Dec 25, 2023
@inomdzhon inomdzhon added this to VKUI Dec 25, 2023
@github-project-automation github-project-automation bot moved this to 🗃 Backlog in VKUI Dec 25, 2023
@inomdzhon
Copy link
Contributor Author

Workaround

/**
 * TODO [@vkontakte/vkui>=5.10.1] Удалить этот патч.
 *
 * [Workaround для VKUI v5.10.0]
 *
 * В VKUI v5.10.0 у `Cell` в режиме `draggable` добавили вертикальный автоскролл страницы, если мы тащим элемент к краю области видимости.
 *
 * НО! Текущая реализация не учитывает, что на странице может не использоваться `html, body { height: 100% }` (или `height: 100vh`).
 *
 * Поэтому мы временно, пока ждём фикса от VKUI, перебиваем `height` у `document.documentElement.getBoundingClientRect()` на `document.documentElement.clientHeight`.
 *
 * @see https://github.com/VKCOM/VKUI/releases/tag/v5.10.0
 */
const patchDocumentElementGetBoundingClientRectFn = () => {
  const origin = document.documentElement.getBoundingClientRect.bind(document.documentElement);
  
  Object.defineProperty(document.documentElement, 'getBoundingClientRect', {
    writable: true,
    value: () => {
      const patchedHeight = document.documentElement.clientHeight;
  
      const { x, y, width } = origin();
  
      return DOMRect.fromRect({ x, y, width, height: patchedHeight });
    },
  });

  return function cleanup() {
    Object.defineProperty(document.documentElement, 'getBoundingClientRect', {
      writable: true,
      value: origin,
    });
  };
}

@inomdzhon inomdzhon added this to the v5.10.1 milestone Jan 22, 2024
@inomdzhon inomdzhon moved this from 🗃 Backlog to 🔧 In progress in VKUI Jan 22, 2024
@inomdzhon inomdzhon modified the milestones: v5.10.1, v6.0.1 Jan 25, 2024
@github-project-automation github-project-automation bot moved this from 🔧 In progress to ✅ Done in VKUI Jan 26, 2024
@inomdzhon inomdzhon linked a pull request Jan 26, 2024 that will close this issue
@vkcom-publisher
Copy link
Contributor

v5.10.1 🎉

@vkcom-publisher
Copy link
Contributor

v6.0.1 🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Archived in project
2 participants