Skip to content

Commit abbe9a9

Browse files
committed
fix(layout): Mini Layouts Align Icons with Hamburger Menu in Dense Mode
1 parent c9cc6a7 commit abbe9a9

File tree

3 files changed

+74
-65
lines changed

3 files changed

+74
-65
lines changed

packages/layout/src/__tests__/__snapshots__/Layout.tsx.snap

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ exports[`Layout mini variant should display only valid nav items at the root in
206206
tabindex="-1"
207207
>
208208
<span
209-
class="rmd-tree-item__content rmd-tree-item__content--clickable rmd-tree-item__content--selected"
209+
class="rmd-tree-item__content rmd-tree-item__content--clickable rmd-tree-item__content--selected rmd-layout-nav__mini-item"
210210
>
211211
<svg
212212
aria-hidden="true"
@@ -239,7 +239,7 @@ exports[`Layout mini variant should display only valid nav items at the root in
239239
tabindex="-1"
240240
>
241241
<span
242-
class="rmd-tree-item__content rmd-tree-item__content--clickable"
242+
class="rmd-tree-item__content rmd-tree-item__content--clickable rmd-layout-nav__mini-item"
243243
>
244244
<svg
245245
aria-hidden="true"
@@ -276,7 +276,7 @@ exports[`Layout mini variant should display only valid nav items at the root in
276276
tabindex="-1"
277277
>
278278
<span
279-
class="rmd-tree-item__content rmd-tree-item__content--clickable"
279+
class="rmd-tree-item__content rmd-tree-item__content--clickable rmd-layout-nav__mini-item"
280280
>
281281
<svg
282282
aria-hidden="true"

packages/layout/src/_mixins.scss

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,10 @@
110110

111111
flex: 1 1 auto;
112112
height: 100%;
113+
114+
&__mini-item {
115+
justify-content: center;
116+
}
113117
}
114118

115119
.rmd-layout-tree {
Lines changed: 67 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import React, { ReactNode } from "react";
2+
import cn from "classnames";
23
import { Divider } from "@react-md/divider";
34
import { TreeItem, TreeItemRenderer } from "@react-md/tree";
45
import { SrOnly } from "@react-md/typography";
@@ -25,70 +26,74 @@ import { LayoutNavigationItem } from "./types";
2526
* @see {@link TreeItemRenderer}
2627
* @see {@link defaultNavigationItemRenderer}
2728
*/
28-
export const defaultMiniNavigationItemRenderer: TreeItemRenderer<LayoutNavigationItem> = (
29-
itemProps,
30-
item,
31-
{ linkComponent, getItemProps, getItemLabel, labelKey }
32-
) => {
33-
const { key, renderChildItems, ...props } = itemProps;
34-
const {
35-
divider,
36-
subheader,
37-
leftAddon,
38-
parentId,
39-
style,
40-
className,
41-
liStyle,
42-
liClassName,
43-
as,
44-
to,
45-
href,
46-
isLink,
47-
contentComponent: propContentComponent,
48-
} = item;
29+
export const defaultMiniNavigationItemRenderer: TreeItemRenderer<LayoutNavigationItem> =
30+
(
31+
itemProps,
32+
item,
33+
{ linkComponent, getItemProps, getItemLabel, labelKey }
34+
) => {
35+
const { key, renderChildItems, ...props } = itemProps;
36+
const {
37+
divider,
38+
subheader,
39+
leftAddon,
40+
parentId,
41+
style,
42+
className,
43+
liStyle,
44+
liClassName,
45+
as,
46+
to,
47+
href,
48+
isLink,
49+
contentComponent: propContentComponent,
50+
} = item;
4951

50-
if (divider && parentId === null) {
51-
return <Divider key={key} />;
52-
}
52+
if (divider && parentId === null) {
53+
return <Divider key={key} />;
54+
}
5355

54-
if (subheader || parentId !== null || !leftAddon || renderChildItems) {
55-
return null;
56-
}
56+
if (subheader || parentId !== null || !leftAddon || renderChildItems) {
57+
return null;
58+
}
5759

58-
let contentComponent = propContentComponent;
59-
if (!contentComponent && isLink !== false && (to || href || isLink)) {
60-
contentComponent = linkComponent;
61-
}
60+
let contentComponent = propContentComponent;
61+
if (!contentComponent && isLink !== false && (to || href || isLink)) {
62+
contentComponent = linkComponent;
63+
}
6264

63-
const { focused, selected, expanded } = itemProps;
64-
const overrides = getItemProps({
65-
...item,
66-
focused,
67-
selected,
68-
expanded,
69-
});
70-
let children: ReactNode = (overrides && overrides.children) || undefined;
71-
if (typeof children === "undefined") {
72-
children = getItemLabel(item, labelKey);
73-
}
65+
const { focused, selected, expanded } = itemProps;
66+
const overrides = getItemProps({
67+
...item,
68+
focused,
69+
selected,
70+
expanded,
71+
});
72+
let children: ReactNode = (overrides && overrides.children) || undefined;
73+
if (typeof children === "undefined") {
74+
children = getItemLabel(item, labelKey);
75+
}
7476

75-
return (
76-
<TreeItem
77-
key={key}
78-
{...props}
79-
as={as}
80-
to={to}
81-
href={href}
82-
isLink={isLink}
83-
contentComponent={contentComponent}
84-
style={overrides?.style ?? style}
85-
className={overrides?.className ?? className}
86-
liStyle={overrides?.liStyle ?? liStyle}
87-
liClassName={overrides?.liClassName ?? liClassName}
88-
textChildren={false}
89-
>
90-
{leftAddon}
91-
<SrOnly>{children}</SrOnly>
92-
</TreeItem>
93-
);
94-
};
77+
return (
78+
<TreeItem
79+
key={key}
80+
{...props}
81+
as={as}
82+
to={to}
83+
href={href}
84+
isLink={isLink}
85+
contentComponent={contentComponent}
86+
style={overrides?.style ?? style}
87+
className={cn(
88+
"rmd-layout-nav__mini-item",
89+
overrides?.className ?? className
90+
)}
91+
liStyle={overrides?.liStyle ?? liStyle}
92+
liClassName={overrides?.liClassName ?? liClassName}
93+
textChildren={false}
94+
>
95+
{leftAddon}
96+
<SrOnly>{children}</SrOnly>
97+
</TreeItem>
98+
);
99+
};

0 commit comments

Comments
 (0)