-
-
Notifications
You must be signed in to change notification settings - Fork 8.5k
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
feat: add page tabbing #946
Conversation
Deploy preview for docusaurus-preview ready! Built with commit c163909 |
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.
This does not close #45 as user who wanted a tab pagging have to manually include the script inside the docs markdown
<script>
function openConfig(evt, configOption) {
var i, tabContent, tabLinks;
tabContent = document.getElementsByClassName("tabcontent");
for (i = 0; i < tabContent.length; i++) {
tabContent[i].style.display = "none";
}
tabLinks = document.getElementsByClassName("tablinks");
for (i = 0; i < tabLinks.length; i++) {
tabLinks[i].className = tabLinks[i].className.replace(" active", "");
}
document.getElementById(configOption).style.display = "block";
evt.currentTarget.className += " active";
}
document.getElementById('userShowcase').style.display = "block";
document.getElementById("userShowcaseLink").className += " active";
</script>
Edit: you might want to look at something like #103 (comment)
@endiliey
what is your suggestion, how should we proceed? |
I prefer the latter. We should make it easy for user to add tabbing without the need to add script on every doc |
@endiliey Can you check it once, would something like this work? I added the script function in DocsLayout.js so that it can be used in any doc page. |
@sbansal3096 When I go to https://deploy-preview-946--docusaurus-preview.netlify.com/docs/en/next/site-config#mandatory-fields It doesn't really go to mandatory fields. Try choosing one tab and the right hand TOC doesn't work as expected if we are in certain page tab. |
@endiliey Yes, you are right. |
I guess the requested changes have been communicated clearly. |
@endiliey I have one more concern. Having same options on the tabs and right hand TOC seems to be vague. Both would provide the same functionality of accessing a part of page quickly and easily. What should we do in such a case? |
I prefer this. |
@endiliey Yeah me too, thanks for quick replies. I'll start working on this. |
I prefer that too. |
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.
Please rebase, we have restructured v1
into a separate folder
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.
See requested changes below.
In addition, if we go to https://deploy-preview-946--docusaurus-preview.netlify.com/docs/en/next/site-config#mandatory-fields
No tabs are active, unlike https://facebook.github.io/react-native/docs/getting-started.html which has gettingStarted
as an active tab
I have to click the tab first before it trim all the other tab's content
v1/lib/core/DocsLayout.js
Outdated
} | ||
tabLinks = document.getElementsByClassName("tablinks"); | ||
for (i = 0; i < tabLinks.length; i++) { | ||
tabLinks[i].className = tabLinks[i].className.replace(" active", ""); |
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.
Let's be more specific and use $
regex
replace(/ active$/, "")
This is to avoid replacing a very special edge case nav activeItem active
to navItem active
in which it should be nav activeItem
for (i = 0; i < tabContent.length; i++) { | ||
tabContent[i].style.display = "none"; | ||
} | ||
tabLinks = document.getElementsByClassName("tablinks"); |
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.
Let's specificly check if tabLinks exist. There is a chance that tabLinks[num]
is undefined and tabLinks[num].className
is accessing property of undefined which yields an error. Similar to any below codes
@endiliey Hey thanks for reviewing the pull request. https://facebook.github.io/react-native/docs/getting-started.html does not have |
Oops, I misconfused the words. You are true, I was referring to Let's get review from @yangshun or @JoelMarcey as well |
@endiliey Thanks a lot. It's really nice of you to reply such quickly. I'll make the changes in implementation soon. |
v1/lib/core/DocsLayout.js
Outdated
<script | ||
dangerouslySetInnerHTML={{ | ||
__html: ` | ||
function openConfig(num) { |
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.
In addition, I think it should not be named openConfig since its not related to config, its more related to tabbing. Use intention revealing names
The num
could be better refactored/changed to the actual id we want to change the class on as well.
I find the name not meaningful enough and using number to refer might not be a good idea.
I recommend something like
function showTabContent(tabContentID) {
// ....
var tabContent = document.getElementById(tabContentID):
//... blablabla
}
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.
The naming part can be changed, but the num part is a bit tougher. The tab content could have an id which can be passed while calling this function. But the id of right side toc cannot be known beforehand unless user explicitly gives each heading in right side toc.
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.
Ok lets do what we can first.
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.
@sbansal3096 Hi 👋 - is it possible to automatically select a tab when you visit a site with tabs? For example you go to https://deploy-preview-946--docusaurus-preview.netlify.com/docs/en/next/site-config and the tabs are shown unselected. And all content is shown. Could you just select "siteConfig Fields" by default so that only that content is shown?
Not a showstopper, but maybe a better user experience.
@JoelMarcey Hey I already discussed regarding this with endiliey before, you might wanna look at this, #946 (comment) |
@sbansal3096 Hmmm. Not sure I understand why we couldn't make my suggestion? You can use JavaScript or maybe even just HTML/CSS force a click on one of the tabs in an automated fashion to mimic what a user would do. Am I missing something? |
@JoelMarcey What if user adds the hashtag in the URL itself, then the default tab won't work, right? This was the reason I chose to left all tabs deselected initially. |
Couldn't JavaScript be used to determine which tab should be selected in that case too? I think with some scripting it could be done. However, I don't feel too strongly about it. If you think the current implementation is the best way to go for now, I am ok moving forward. |
This is a great feature; many thanks @sbansal3096 for implementing that. 👏 👏 I noticed the discussion about the unselected tabs at the start... My 2 cents here: From a user perspective (my view), I'd not (or never) expect to see all the content at the start. Also, it seems that once a tab is selected, you can't go back to the initial state (all unselected) without reloading the page, so, at first glance, this behaviour looks like a bug with the tabs... I don't know what could be changed to make it work in that way, but I should admit that IMHO:
Thanks |
My 2 cents are the current behavior are indeed weird from user perspective. |
@sbansal3096 @endiliey -- We are going through our pull requests for our next release. We were not sure if this was ready to go yet. I know @yangshun was a bit concerned that this directly modifies DocsLayout, the code of which is on every docs page. Not a showstopper, assuming this is ready, but if it is not ready, then maybe we want to determine whether we can go about this another way. |
@JoelMarcey I agree, this is surely not ready. It has some issues for concern. I am open for suggestions. |
I'm gonna close this one because I think we already have another better solution shipped in Docusaurus. Thank you for the effort by the way 😉 |
@endiliey I read the latest document (2.0.0-alpha.72), but I can not find the 'better solution', where I can get it? |
This issue for Docusaurus v1. If you're using v1, then refer to this page - https://v1.docusaurus.io/docs/en/doc-markdown#language-specific-code-tabs But we recommend using v2 and it seems like you're using it also. In that case, refer to https://docusaurus.io/docs/markdown-features/tabs |
@yangshun I know the 'tabs' in the v2, and I also tried it out, but it is not what I want that has been mentioned before
|
@ziscloud It is not clear to me what you want exactly, and why v2 tabs aren't a good fit your you |
Not sure exactly what @ziscloud means, but the v2 tabs have fewer features than what's been discussed on this issue. The table of contents does not change when a new tab is clicked, making it very confusing when using tabs and the table of contents features at the same time: @slorber what's missing from v2 tabs IMO:
|
@kevinmpowell In v2 the Tabs is just a normal React component, and it seems there's no interest in making it any more special than user-defined components (which means it doesn't, and won't, have access to the TOC comp at all, neither would the TOC implementation know about the existence of Tabs): #5343 |
My recommendation would be to try not to put headings and stuff into the tabs. It's not a common thing to do IMO. |
Would love to see this feature (paged tabs) get prioritized. It's different than what the current tab component offers. The Stripe.com docs are a great example of this. Notice when you switch tabs between "dashboard" and "api" the urls and table of contents updates. https://stripe.com/docs/billing/subscription-resource cc: @endiliey |
@adamsoffer Endiliey is not there anymore unfortunately (https://docusaurus.io/blog/2020/01/07/tribute-to-endi) That's an interesting feature that I never saw before. That's worth opening a new feature request for that, although I doubt we'd have the bandwidth to implement it, as it doesn't look too easy. Please post a gif in the feature request, otherwise the Stripe doc may change and we may lose context |
Motivation
Fixes #45
Add page tabbing infrastructure to the Docusaurus site.
Have you read the Contributing Guidelines on pull requests?
Yes
Test Plan