-
Notifications
You must be signed in to change notification settings - Fork 159
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(table-of-contents): ensure anchor is visible upon jump-to-content #4297
fix(table-of-contents): ensure anchor is visible upon jump-to-content #4297
Conversation
Introduces `bx--tableofcontents__contents` CSS class that ensures `<a name="anchorname">` is visible upon getting scroll to by selection of an item in `<dds-table-of-contents>`. Refs carbon-design-system#4264.
Deploy preview created for package Built with commit: 65c4ba75b4063473dfb440a143b9f7c5d658032d |
Deploy preview created for package Built with commit: 65c4ba75b4063473dfb440a143b9f7c5d658032d |
<a name="3" data-title="Section - 3"></a> | ||
<h3>Section - 3</h3> | ||
<p>Section 3 content</p> | ||
<div class="bx--tableofcontents__contents"> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@asudoh are we replying on adopters to add this wrapper class? Anyway this element can be transcluded instead?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@asudoh are we replying on adopters to add this wrapper class?
Yes. Seems that we need this kind of wrapper class for React, too, given navigating directly to hashbang URL fails there.
Anyway this element can be transcluded instead?
Do you have any more details here...? Thanks!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What I mean is can we add the wrapper div for the user instead of asking them to add it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for clarifying @jeffchew! I thought of making it automatic, but the problem is that our style (shadow DOM style) doesn't have direct control over the content style, and we allow arbitrary content for <dds-table-of-contents>
. Therefore it looks like it's more prudent for us to clearly document that user has to use our CSS class to adjust the anchor position. I used below wording as an explanation of what the example code does, but good to hear better wording, etc.:
💡
bx--tableofcontents__contents
class in the content<div>
ensures the<h3>
is visible by navigating to a hashbang URL (e.g.https://yoursite.com/yourpage#2
).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good thanks @asudoh!
Related Ticket(s)
Refs #4264.
Description
Introduces
bx--tableofcontents__contents
CSS class that ensures<a name="anchorname">
is visible upon getting scroll to by selection of an item in<dds-table-of-contents>
.Changelog
New
bx--tableofcontents__contents
CSS class.Removed
InsersectionObserver
for scroll hijacking code. It's effectively replaced with the newbx--tableofcontents__contents
CSS class.