Skip to content

Commit abc5d21

Browse files
authored
Add visible focus indicator for app bar (#968)
1 parent 56c05ba commit abc5d21

File tree

3 files changed

+23
-9
lines changed

3 files changed

+23
-9
lines changed

src/components/App/AppBar.scss

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,5 +53,11 @@
5353
&:not(.mdc-tab--active) .mdc-tab__text-label {
5454
color: var(--mdc-theme-on-surface);
5555
}
56+
.mdc-tab__ripple:hover::before {
57+
opacity: 0.5;
58+
}
59+
.mdc-tab__ripple.mdc-ripple-upgraded--background-focused::before {
60+
opacity: 0.5;
61+
}
5662
}
5763
}

src/components/App/AppBar.tsx

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -48,12 +48,18 @@ export const AppBar: React.FC<React.PropsWithChildren<Props>> = ({
4848
</Tab>
4949
));
5050

51-
const activeTabIndex = navRoutes.findIndex((r) =>
52-
matchPath(location.pathname, {
53-
path: r.path,
54-
exact: r.exact,
55-
})
56-
);
51+
const [activeTabIndex, setActiveTab] = React.useState(0);
52+
53+
React.useEffect(() => {
54+
setActiveTab(
55+
navRoutes.findIndex((r) =>
56+
matchPath(location.pathname, {
57+
path: r.path,
58+
exact: r.exact,
59+
})
60+
)
61+
);
62+
}, [location.pathname, navRoutes]);
5763

5864
return (
5965
<ThemeProvider
@@ -73,7 +79,11 @@ export const AppBar: React.FC<React.PropsWithChildren<Props>> = ({
7379
</Typography>
7480
</div>
7581
</div>
76-
<TabBar theme="onSurface" activeTabIndex={activeTabIndex}>
82+
<TabBar
83+
theme="onSurface"
84+
activeTabIndex={activeTabIndex}
85+
onActivate={(evt) => setActiveTab(evt.detail.index)}
86+
>
7787
{tabs}
7888
</TabBar>
7989
</TopAppBar>

src/index.tsx

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,6 @@ const root = createRoot(container!);
5858
// https://github.com/remix-run/react-router/issues/7870
5959
root.render(
6060
<RMWCProvider
61-
// Globally disable ripples
62-
ripple={false}
6361
typography={{
6462
/** Make headline3 <h3> instaed of div or span */
6563
headline3: 'h3',

0 commit comments

Comments
 (0)