Skip to content

Commit

Permalink
Merge pull request #104 from PaulGehin/focus-button
Browse files Browse the repository at this point in the history
Focus indicator and accessibility-compliant contrast for buttons
  • Loading branch information
garronej authored Jul 3, 2023
2 parents 2128b1c + d36c9a7 commit 0398988
Show file tree
Hide file tree
Showing 8 changed files with 32 additions and 21 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "onyxia-ui",
"version": "0.56.0",
"version": "0.56.1",
"description": "A uli toolkit, like material-ui but with stronger typing and more opinionated",
"repository": {
"type": "git",
Expand Down
2 changes: 1 addition & 1 deletion src/Breadcrump.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ const { Section } = (() => {
? {}
: {
"cursor": "pointer",
"&:hover": {
"&:hover, &:focus": {
"fontWeight": hoverFontWeight,
"color": theme.colors.useCases.typography.textPrimary,
},
Expand Down
31 changes: 17 additions & 14 deletions src/Button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import MuiButton from "@mui/material/Button";
import { capitalize } from "tsafe/capitalize";
import { assert } from "tsafe";
import type { Equals } from "tsafe/Equals";
import { breakpointsValues } from "./lib/breakpoints";
import { breakpointsValues } from "./lib";
import { variantNameUsedForMuiButton } from "./lib/typography";
import { pxToNumber } from "./tools/pxToNumber";

Expand Down Expand Up @@ -98,6 +98,7 @@ export function createButton<IconId extends string = never>(params?: {

return (
<MuiButton
disableFocusRipple
ref={ref}
className={cx(classes.root, className)}
//There is an error in @mui/material types, this should be correct.
Expand Down Expand Up @@ -175,19 +176,21 @@ export function createButton<IconId extends string = never>(params?: {
const hoverTextColor = (() => {
switch (theme.isDarkModeEnabled) {
case true:
return theme.colors.palette[
(() => {
switch (variant) {
case "primary":
return "light";
case "secondary":
case "ternary":
return "dark";
}
})()
].main;
switch (variant) {
case "ternary":
return theme.colors.useCases.surfaces.background;
default:
return theme.colors.palette.dark.main;
}
case false:
return theme.colors.palette.light.main;
switch (variant) {
case "primary":
return theme.colors.palette.dark.main;
case "secondary":
return theme.colors.palette.light.main;
case "ternary":
return theme.colors.useCases.surfaces.background;
}
}
})();

Expand Down Expand Up @@ -266,7 +269,7 @@ export function createButton<IconId extends string = never>(params?: {
"color": textColor,
},

"&:hover": {
"&:hover, &:focus": {
"backgroundColor": hoverBackgroundColor,
"& .MuiSvgIcon-root": {
"color": hoverTextColor,
Expand Down
2 changes: 1 addition & 1 deletion src/ButtonBarButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ export function createButtonBarButton<IconId extends string = never>(params: {
"& > *": {
"transition": "none",
},
"&:hover.MuiButton-text": {
"&:hover.MuiButton-text, &:focus.MuiButton-text": {
"color": theme.colors.useCases.typography.textPrimary,
"borderBottomColor": theme.colors.useCases.buttons.actionActive,
"boxSizing": "border-box",
Expand Down
2 changes: 1 addition & 1 deletion src/IconButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ export function createIconButton<IconId extends string = never>(params?: {
})((theme, { disabled }) => ({
"root": {
"padding": theme.spacing(2),
"&:hover": {
"&:hover, &:focus": {
"backgroundColor": "unset",
"& svg": {
"color": theme.colors.useCases.buttons.actionHoverPrimary,
Expand Down
4 changes: 4 additions & 0 deletions src/LanguageSelect.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ export function createLanguageSelect<Language extends string>(params: {
<MuiButton
className={cx(classes.button, className)}
ref={buttonRef}
disableRipple
aria-owns={languageMenu ? menuId : undefined}
aria-haspopup="true"
aria-label={changeLanguageText ?? "change language"}
Expand Down Expand Up @@ -166,6 +167,9 @@ export function createLanguageSelect<Language extends string>(params: {
return 0;
}
})(),
"&.Mui-focusVisible": {
"outline": "-webkit-focus-ring-color auto 1px",
},
},
"menu": {
"& .Mui-selected": {
Expand Down
8 changes: 6 additions & 2 deletions src/LeftBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -313,11 +313,15 @@ export function createLeftBar<IconId extends string>(params?: {
"textDecoration": "none",
"display": "flex",
"cursor": "pointer",
[`&:hover .${classes.iconHoverBox}`]: {
[["hover", "focus"]
.map(name => `&:${name} .${classes.iconHoverBox}`)
.join(", ")]: {
"backgroundColor":
theme.colors.useCases.surfaces.background,
},
[`&:hover .${classes.typoWrapper}`]: {
[["hover", "focus"]
.map(name => `&:${name} .${classes.typoWrapper}`)
.join(", ")]: {
"backgroundColor": !isCollapsed
? theme.colors.useCases.surfaces.background
: undefined,
Expand Down
2 changes: 1 addition & 1 deletion src/lib/color.ts
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ export function createDefaultColorUseCases(
},
"buttons": {
"actionHoverPrimary":
palette.focus[isDarkModeEnabled ? "light" : "main"],
palette.focus[isDarkModeEnabled ? "light2" : "main"],
"actionHoverSecondary": isDarkModeEnabled
? palette.light.light
: palette.dark.main,
Expand Down

0 comments on commit 0398988

Please sign in to comment.