mirror of
https://github.com/lrnselfreliance/wrolpi.git
synced 2026-12-03 21:29:59 -05:00
bookmarks: mark More current when the editor is folded inside it; rem indents in the mobile menu
Found on the QA Pi at a width where Bookmarks overflows into More: the More button carried no mark on /more/bookmarks, because the bookmarks link has no `to` for isLinkActive to match. isLinkActive now knows the bookmarks link owns its editor page, and the Bookmarks tab uses the same rule. The mobile menu's directory labels sat a few pixels left of the labels around them: the indent was in em, and a Menu.Label is set smaller than a Menu.Item. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
This commit is contained in:
parent
b3c51c8b49
commit
88b261ae77
3 changed files with 19 additions and 6 deletions
|
|
@ -26,7 +26,9 @@ function bookmarkItemProps(node) {
|
|||
*
|
||||
* `nested` draws a directory as a flyout (Menu.Sub), which opens beside the menu on hover.
|
||||
* Without it a directory is a labelled, indented run of items instead: the mobile
|
||||
* hamburger is the one place bookmarks are shown where a flyout cannot be hovered.
|
||||
* hamburger is the one place bookmarks are shown where a flyout cannot be hovered. The
|
||||
* indent is in rem: a label is set smaller than an item, so an em indent would put a
|
||||
* directory's label a few pixels left of the items beside it.
|
||||
*/
|
||||
export function BookmarkMenuItems({nodes, nested = true, depth = 0}) {
|
||||
if (!nodes || nodes.length === 0) {
|
||||
|
|
@ -47,14 +49,14 @@ export function BookmarkMenuItems({nodes, nested = true, depth = 0}) {
|
|||
</Menu.Sub>;
|
||||
}
|
||||
return <React.Fragment key={node.id}>
|
||||
<Menu.Label style={{paddingLeft: `${0.75 + depth}em`}}>{node.name}</Menu.Label>
|
||||
<Menu.Label style={{paddingLeft: `${0.75 + depth}rem`}}>{node.name}</Menu.Label>
|
||||
<BookmarkMenuItems nodes={node.children} nested={false} depth={depth + 1}/>
|
||||
</React.Fragment>;
|
||||
}
|
||||
return <Menu.Item
|
||||
key={node.id}
|
||||
{...bookmarkItemProps(node)}
|
||||
style={nested ? undefined : {paddingLeft: `${0.75 + depth}em`}}
|
||||
style={nested ? undefined : {paddingLeft: `${0.75 + depth}rem`}}
|
||||
rightSection={node.new_tab ? <Icon name='external' size='small'/> : undefined}
|
||||
>
|
||||
{node.name}
|
||||
|
|
|
|||
|
|
@ -166,6 +166,11 @@ NavDropdownTrigger.displayName = 'NavDropdownTrigger';
|
|||
* the hooks that would answer it cannot be called in a loop.
|
||||
*/
|
||||
export const isLinkActive = (pathname, link) => {
|
||||
// The Bookmarks menu owns only its editor page: a bookmark pointing at /videos does
|
||||
// not make the menu own the Videos section.
|
||||
if (link.bookmarks) {
|
||||
return pathname === EDIT_BOOKMARKS_PATH || pathname.startsWith(`${EDIT_BOOKMARKS_PATH}/`);
|
||||
}
|
||||
// An off-site link (Help) is never the current section.
|
||||
if (!link.to || /^[a-z]+:\/\//i.test(link.to)) return false;
|
||||
const to = link.to.length > 1 ? link.to.replace(/\/+$/, '') : link.to;
|
||||
|
|
@ -202,12 +207,12 @@ function DropdownLinks({link}) {
|
|||
|
||||
/**
|
||||
* The Bookmarks tab: a dropdown that opens on hover as well as on click, holding the
|
||||
* user's bookmarks and the link to edit them. Marked current on the editor page only;
|
||||
* a bookmark pointing at /videos does not make this tab own the Videos section.
|
||||
* user's bookmarks and the link to edit them. Marked current on the editor page only
|
||||
* (see isLinkActive).
|
||||
*/
|
||||
function BookmarksDropdown({link}) {
|
||||
const {pathname} = useLocation();
|
||||
const holdsCurrent = pathname === EDIT_BOOKMARKS_PATH || pathname.startsWith(`${EDIT_BOOKMARKS_PATH}/`);
|
||||
const holdsCurrent = isLinkActive(pathname, link);
|
||||
return <Menu position='bottom-start' withinPortal trigger='click-hover' openDelay={100} closeDelay={200}>
|
||||
<Menu.Target>
|
||||
<NavDropdownTrigger text={link.text} className={holdsCurrent ? 'active' : undefined}/>
|
||||
|
|
|
|||
|
|
@ -293,6 +293,12 @@ describe('NavBar bookmarks', () => {
|
|||
expect(currentTab()).toEqual([]);
|
||||
});
|
||||
|
||||
it('marks More when the editor page is folded inside it', () => {
|
||||
useBarWidth(200);
|
||||
renderWithBookmarks('/more/bookmarks', bookmarks);
|
||||
expect(screen.getByRole('button', {name: /More/})).toHaveClass('active');
|
||||
});
|
||||
|
||||
it('does not own the section a bookmark points at', () => {
|
||||
renderWithBookmarks('/videos/channel', bookmarks);
|
||||
expect(screen.getByRole('button', {name: /Bookmarks/})).not.toHaveClass('active');
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue