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

fix(CustomSelect): Use onMouseOver instead onMouseEnter #2328

Merged
merged 2 commits into from
Mar 30, 2022

Conversation

inomdzhon
Copy link
Contributor

@inomdzhon inomdzhon commented Mar 29, 2022

Компонент

CustomSelect

Какая была проблема?

При параметре searchable, обновляется "ребёнок", из-за чего onMouseEnter не срабатывает в следующих кейсах:

  1. До загрузки выпадающего списка, курсор мышки находится над произвольным элементом этого списка.

    Лечение: только увод курсора мыши и возвращении его обратно вызывает событие onMouseEnter на этот элемент.

  2. Если это тач-устройство.

    Лечение: нужно нажать на какой-нибудь произвольный элемент списка, после чего onMouseEnter будет работать на соседние элементы, но не на тот, на который нажали в первый раз.

Более подробно по ссылке facebook/react#13956 (comment)

Как починилось?

onMouseEnter был заменён на onMouseOver.

onMouseOver отличается тем, что он будет дополнительно вызываться, если мы указали на ребёнка элемента. Чтобы оптимизировать это, добавляем при проверку перед обновлением состояния в функции focusOptionByIndex() компонента

this.setState((prevState) =>
// Это оптимизация, прежде всего, под `onMouseOver`
prevState.focusedOptionIndex !== index
? {
focusedOptionIndex: index,
}
: null
);

@codesandbox-ci
Copy link

codesandbox-ci bot commented Mar 29, 2022

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

Latest deployment of this branch, based on commit 8f6e99e:

Sandbox Source
VKUI - default example Configuration

@github-actions
Copy link
Contributor

github-actions bot commented Mar 29, 2022

size-limit report 📦

Path Size
JS 81.7 KB (+0.02% 🔺)
JS, unstable 25.71 KB (0%)
CSS 41.9 KB (0%)
CSS, unstable 1003 B (0%)

@github-actions
Copy link
Contributor

👀 Styleguide deployed

See the styleguide for this PR at https://vkcom.github.io/VKUI/pull/2328/

@github-actions
Copy link
Contributor

github-actions bot commented Mar 29, 2022

Warnings
⚠️

1 changed screenshots found — review & update them via "Update Screenshots" action before merging.

Changed screenshots

chipsselect-scrolls-to-item-via-arrows-1

Code coverage

lines3520 / 452177.85%
statements3586 / 460677.85%
functions791 / 98280.54%
branches2927 / 419469.79%
branchesTrue0 / 0100.00%

Generated by 🚫 dangerJS against 8ccd2d2

eugpoloz
eugpoloz previously approved these changes Mar 29, 2022
Copy link
Contributor

@eugpoloz eugpoloz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ином, ты 🔥

@eugpoloz eugpoloz merged commit 08d5a22 into master Mar 30, 2022
@eugpoloz eugpoloz deleted the bugfix/CustomSelect-problem-with-onMouseEnter branch March 30, 2022 08:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants