Skip to content

Commit 4547519

Browse files
committed
chore: clean up base nav button
1 parent 58fdd26 commit 4547519

File tree

1 file changed

+17
-7
lines changed

1 file changed

+17
-7
lines changed

site/src/components/PaginationWidget/PaginationNavButtons.tsx

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,11 @@ function BaseNavButton({
7474
const theme = useTheme();
7575
const [showDisabledMessage, setShowDisabledMessage] = useState(false);
7676

77+
// Inline state sync - this is safe/recommended by the React team in this case
78+
if (!disabled && showDisabledMessage) {
79+
setShowDisabledMessage(false);
80+
}
81+
7782
useEffect(() => {
7883
if (!showDisabledMessage) {
7984
return;
@@ -84,19 +89,24 @@ function BaseNavButton({
8489
disabledMessageTimeout,
8590
);
8691

87-
return () => window.clearTimeout(timeoutId);
92+
return () => {
93+
setShowDisabledMessage(false);
94+
window.clearTimeout(timeoutId);
95+
};
8896
}, [showDisabledMessage, disabledMessageTimeout]);
8997

90-
// Using inline state sync to help MUI render accurately more quickly; same
91-
// idea as the useEffect approach, but state changes flush faster
92-
if (!disabled && showDisabledMessage) {
93-
setShowDisabledMessage(false);
94-
}
95-
9698
return (
9799
<Tooltip title={disabledMessage} open={showDisabledMessage}>
100+
{/*
101+
* Going more out of the way to avoid attaching the disabled prop directly
102+
* to avoid unwanted side effects of using the prop:
103+
* - Not being focusable/keyboard-navigable
104+
* - Not being able to call functions in response to invalid actions
105+
* (mostly for giving direct UI feedback to those actions)
106+
*/}
98107
<Button
99108
aria-label={ariaLabel}
109+
aria-disabled={disabled}
100110
css={
101111
disabled && {
102112
borderColor: theme.palette.divider,

0 commit comments

Comments
 (0)