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: proper collapsing of long element #5694

Merged
merged 5 commits into from
Oct 15, 2021
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -197,21 +197,8 @@ function CollapsibleBase({
return;
}

const el = collapsibleRef.current!;
const currentCollapsibleElementHeight = el.style.height;

if (
!collapsed &&
parseInt(currentCollapsibleElementHeight, 10) === el.scrollHeight
) {
applyCollapsedStyle(el, false);
onCollapseTransitionEnd?.(false);
}

if (currentCollapsibleElementHeight === CollapsedStyles.height) {
applyCollapsedStyle(el, true);
onCollapseTransitionEnd?.(true);
}
applyCollapsedStyle(collapsibleRef.current!, collapsed);
onCollapseTransitionEnd?.(collapsed);
}}
className={className}>
{children}
Expand Down
15 changes: 12 additions & 3 deletions website/_dogfooding/docs-tests-sidebars.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,16 @@ module.exports = {
{
type: 'category',
label: 'Huge sidebar category',
items: generateHugeSidebarItems(4),
items: [
...generateHugeSidebarItems(4),
...[
{
type: 'link',
href: '/',
label: 'Test Test test test test test test',
},
],
],
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why ... instead of just adding the item at the beginning?

Also I'd suggest adding that example at the very beginning. Adding it at the end makes it not clear that it actually wraps, because we don't see it moving from 1 line to 2 lines (at least on my screen). I had to remove the scrollbar with devtools to be sure it does.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sorry, it didn't seem to matter to me, but I moved it to top of list.

reintroduces an annoying behavior

Yes, but it still not as annoying as the current issue. I still can't find better solution.

Copy link
Collaborator

Choose a reason for hiding this comment

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

The wrapping affects only a few sites (it's worst but unless bad luck the last item remains clickable).
The collapsible problem is a smaller problem but it affects all sites in multiple places.

I'd rather wait and find a better solution.

IMHO the solution we want is to ensure the category label does not wrap anymore: #5254 It would solve 2 issues at once

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I disagree, the current issue affects to more sites (not just those two sites) and therefore more serious. The other issue with multiple clicks is a rare case, though. Well then let's initially calculate collapsible element height with possible scrollbar. Any objections?

Copy link
Collaborator

@slorber slorber Oct 15, 2021

Choose a reason for hiding this comment

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

I think we won't agree on this, unfortunately, but I don't like the idea to fix an issue (that none or very few users reported as a major problem) by introducing a regression somewhere else: we must find a way to fix both issues at once.


This new solution is not ideal either.

A scrollbar can temporarily appear as you click:

Oct-15-2021 12-14-04

And if you reduce the size of the category that has a wrapping element, you'll notice some extra height added at the end, and then "fixed" on animation end.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think you should consider realistic usage scenarios first. So the scrollbar will not be displayed if the user clicks once -- this is main realistic use case. Why would anyone want to click on a category many many times?

"no user reported" -- that's because users mostly don't care on it, they came to docs site for information, they are not testers. Better ask the owner of Redux site about this issue, he's hardly aware of it because he doesn't test the whole site by clicking on every category, I guess.

},
{
type: 'link',
Expand All @@ -46,8 +55,8 @@ module.exports = {

function generateHugeSidebarItems() {
const maxLevel = 4;
const linksCount = 5;
const categoriesCount = 5;
const linksCount = 8;
const categoriesCount = 8;

function generateRecursive(maxLevel, currentLevel = 0) {
if (currentLevel === maxLevel) {
Expand Down