-
-
Notifications
You must be signed in to change notification settings - Fork 8.7k
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
Finish go to selected paged from category sidebar #4323
Closed
Closed
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
5eb20d6
added go_to config
softwarecurator 112ec81
This is temp
softwarecurator 6ba1686
added go_to functionality
softwarecurator 7765199
updates from pull request
softwarecurator 1c3f322
Merge branch 'master' into go-to-selected-page
ben-qnimble 7525e54
Address code review comments from pull request #3898
ben-qnimble 8d319d1
Pass all automated build and deplay and lint tests
ben-qnimble 8d6dd4b
Fix typo in link for Getting Started category. Remove link from Advan…
ben-qnimble 42d59e0
Remove unused function
ben-qnimble 314d44d
formatting fix to pass prettier check
ben-qnimble a2e8793
Per @lex111 code review comment, remove manually set attributes for e…
ben-qnimble b8e9f03
Change default/empty for category link from empty string to undefined
ben-qnimble 1201e5d
Make SidebarItemCategory link object get proper typing
ben-qnimble afc8a2f
Switch from useState to useMemo for storing category link reference
ben-qnimble e2998f7
Remove breaks after returns as circle flags as unreachable code
ben-qnimble File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,7 +5,7 @@ | |
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
import React, {useState, useCallback, useEffect, useRef} from 'react'; | ||
import React, {useState, useMemo, useCallback, useEffect, useRef} from 'react'; | ||
import clsx from 'clsx'; | ||
import {useThemeConfig, isSamePath} from '@docusaurus/theme-common'; | ||
import useUserPreferencesContext from '@theme/hooks/useUserPreferencesContext'; | ||
|
@@ -49,6 +49,7 @@ function DocSidebarItemCategory({ | |
onItemClick, | ||
collapsible, | ||
activePath, | ||
link, | ||
...props | ||
}) { | ||
const {items, label} = item; | ||
|
@@ -64,6 +65,24 @@ function DocSidebarItemCategory({ | |
} | ||
return isActive ? false : item.collapsed; | ||
}); | ||
const initialLink = useMemo(() => { | ||
if (item.link) { | ||
if (Object.hasOwnProperty.call(item.link, 'type')) { | ||
switch (item.link.type) { | ||
case 'doc': | ||
return item.link.id; | ||
case 'link': | ||
return item.link.href; | ||
default: | ||
return undefined; | ||
} | ||
} else { | ||
return undefined; | ||
} | ||
} else { | ||
return undefined; | ||
} | ||
}, [item.link]); | ||
|
||
const menuListRef = useRef<HTMLUListElement>(null); | ||
const [menuListHeight, setMenuListHeight] = useState<string | undefined>( | ||
|
@@ -86,11 +105,9 @@ function DocSidebarItemCategory({ | |
const handleItemClick = useCallback( | ||
(e) => { | ||
e.preventDefault(); | ||
|
||
if (!menuListHeight) { | ||
handleMenuListHeight(); | ||
} | ||
|
||
setTimeout(() => setCollapsed((state) => !state), 100); | ||
}, | ||
[menuListHeight], | ||
|
@@ -106,17 +123,21 @@ function DocSidebarItemCategory({ | |
'menu__list-item--collapsed': collapsed, | ||
})} | ||
key={label}> | ||
<a | ||
<Link | ||
to={initialLink} | ||
className={clsx('menu__link', { | ||
'menu__link--sublist': collapsible, | ||
'menu__link--active': collapsible && isActive, | ||
[styles.menuLinkText]: !collapsible, | ||
[styles.menuLinkText]: !collapsible && initialLink === undefined, | ||
})} | ||
{...{ | ||
isNavLink: true, | ||
onClick: onItemClick, | ||
}} | ||
onClick={collapsible ? handleItemClick : undefined} | ||
href={collapsible ? '#!' : undefined} | ||
{...props}> | ||
{label} | ||
</a> | ||
</Link> | ||
<ul | ||
className="menu__list" | ||
ref={menuListRef} | ||
|
@@ -132,6 +153,7 @@ function DocSidebarItemCategory({ | |
<DocSidebarItem | ||
tabIndex={collapsed ? '-1' : '0'} | ||
key={childItem.label} | ||
link={link} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why bind this to the children elements? Only the category with |
||
item={childItem} | ||
onItemClick={onItemClick} | ||
collapsible={collapsible} | ||
|
@@ -268,6 +290,7 @@ function DocSidebar({ | |
<DocSidebarItem | ||
key={item.label} | ||
item={item} | ||
link={item.type === 'category' ? item.link : undefined} | ||
onItemClick={(e) => { | ||
e.target.blur(); | ||
setShowResponsiveSidebar(false); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
We need to validate that the link attribute is valid in this function + add unit tests
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.
I might need some help on this one