Skip to content

✨ [bento][amp-sidebar] Add check for RTL docs for default side#31821

Merged
krdwan merged 7 commits intoampproject:masterfrom
krdwan:amp-sidebar-rtl
Jan 14, 2021
Merged

✨ [bento][amp-sidebar] Add check for RTL docs for default side#31821
krdwan merged 7 commits intoampproject:masterfrom
krdwan:amp-sidebar-rtl

Conversation

@krdwan
Copy link
Copy Markdown
Contributor

@krdwan krdwan commented Jan 6, 2021

Sidebar tracker: #31366


If side attribute / prop is not provided to the sidebar component. The component first checks if the document is an RTL document and if so assigns default side to right, otherwise defaults to left.

todo: add tests

@krdwan krdwan requested review from caroqliu and dvoytenko January 6, 2021 16:24
@krdwan krdwan requested a review from caroqliu January 6, 2021 21:55
@krdwan krdwan requested a review from dvoytenko January 12, 2021 18:00
Copy link
Copy Markdown
Contributor

@dvoytenko dvoytenko left a comment

Choose a reason for hiding this comment

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

Ok. This looks pretty good. Just a couple of comments.

return;
}
setSide(calculateSide(sideProp, sidebarElement.ownerDocument));
}, [sideProp, side, mounted]);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Do we need mounted here?

Copy link
Copy Markdown
Contributor Author

@krdwan krdwan Jan 13, 2021

Choose a reason for hiding this comment

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

Yes, because on the initial render, mounted = false so we don't get sidebarRef and end up exiting early without doing the setSide calculation. 😕

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Got it.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Though it's probably worth commenting this fact.

Copy link
Copy Markdown
Contributor

@caroqliu caroqliu Jan 14, 2021

Choose a reason for hiding this comment

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

Just a thought - I'm not convinced we should conditionally render sideBarRef with mounted && <>...</> if we need to work around sidebarRef only sometimes being defined. We now also add hidden styles for sidebar and mask before open anyway, so the conditional render is not even getting us out of doing that.

In the future we will also likely want to always render the content if we want sidebar content to be matchable with content-visibility: hidden-matchable.

However I don't think we should have to do this in this PR.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I agree this is definitely worth exploring!

return;
}
setSide(isRTL(sidebarElement.ownerDocument) ? Side.RIGHT : Side.LEFT);
}, [side, mounted]);
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Only reaches here if sideProp is undefined so we can directly use document.dir to set side


if (!side) {
return;
}
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Hide element directly with hidden attribute on rendered output. (Removed setStyle call)

@krdwan krdwan requested a review from dvoytenko January 13, 2021 22:08
@krdwan krdwan merged commit 0883295 into ampproject:master Jan 14, 2021
PetrBlaha pushed a commit to PetrBlaha/amphtml that referenced this pull request Jan 28, 2021
…oject#31821)

* Add check for RTL docs for default side

* Review comments

* Use state in sidebar

* Updated design

* Updated sidebar per review comments

* Add tests to rtl

* Fix a typo
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants