Skip to content

Commit

Permalink
feat: utilize outline instead of box-shadow for :focus-visible
Browse files Browse the repository at this point in the history
…pseudo-style rendering
  • Loading branch information
cheton committed Oct 7, 2023
1 parent 27e18a7 commit 280c405
Show file tree
Hide file tree
Showing 10 changed files with 51 additions and 35 deletions.
8 changes: 4 additions & 4 deletions packages/react/src/checkbox/CheckboxControlBox.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ const CheckboxControlBox = forwardRef((
const checkedAndDisabledBorderColor = disabledBorderColor;

// outline color
const focusOutlineColor = {
const focusVisibleOutlineColor = {
dark: `${variantColor}:60`,
light: `${variantColor}:60`,
}[colorMode];
Expand All @@ -121,8 +121,8 @@ const CheckboxControlBox = forwardRef((
opacity: 0.28,
},
[getCheckboxControlBoxSelector(':focus-visible')]: {
outlineColor: focusVisibleOutlineColor,
outlineStyle: 'solid',
outlineColor: focusOutlineColor,
outlineWidth: '1h',
},
[getCheckboxControlBoxSelector(':checked')]: {
Expand Down Expand Up @@ -181,7 +181,7 @@ const CheckboxControlBox = forwardRef((
}[colorMode];

// outline color
const focusOutlineColor = {
const focusVisibleOutlineColor = {
dark: `${variantColor}:60`,
light: `${variantColor}:60`,
}[colorMode];
Expand All @@ -196,8 +196,8 @@ const CheckboxControlBox = forwardRef((
color: hoverColor,
},
[getCheckboxControlBoxSelector('[data-indeterminate]:focus-visible')]: {
outlineColor: focusVisibleOutlineColor,
outlineStyle: 'solid',
outlineColor: focusOutlineColor,
outlineWidth: '1h',
},
[getCheckboxControlBoxSelector('[data-indeterminate]:disabled')]: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,8 @@ input[type="checkbox"]:disabled+.emotion-4 {
}
input[type="checkbox"]:focus-visible+.emotion-4 {
outline-style: solid;
outline-color: var(--tonic-colors-blue-60);
outline-style: solid;
outline-width: var(--tonic-sizes-1h);
}
Expand Down Expand Up @@ -208,8 +208,8 @@ input[type="checkbox"]:disabled+.emotion-16 {
}
input[type="checkbox"]:focus-visible+.emotion-16 {
outline-style: solid;
outline-color: var(--tonic-colors-blue-60);
outline-style: solid;
outline-width: var(--tonic-sizes-1h);
}
Expand Down Expand Up @@ -316,8 +316,8 @@ input[type="checkbox"]:disabled+.emotion-28 {
}
input[type="checkbox"]:focus-visible+.emotion-28 {
outline-style: solid;
outline-color: var(--tonic-colors-blue-60);
outline-style: solid;
outline-width: var(--tonic-sizes-1h);
}
Expand Down Expand Up @@ -418,8 +418,8 @@ input[type="checkbox"][data-indeterminate]:hover:not(:disabled)+.emotion-52 {
}
input[type="checkbox"][data-indeterminate]:focus-visible+.emotion-52 {
outline-style: solid;
outline-color: var(--tonic-colors-blue-60);
outline-style: solid;
outline-width: var(--tonic-sizes-1h);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,10 @@ exports[`Menu should render correctly 1`] = `
}
.emotion-16:focus-visible {
box-shadow: inset 0 0 0 .125rem #1e5ede;
outline-color: var(--tonic-colors-blue-60);
outline-offset: calc(var(--tonic-space-1h) * -1);
outline-style: solid;
outline-width: var(--tonic-sizes-1h);
}
.emotion-16[aria-selected=true],
Expand Down
9 changes: 5 additions & 4 deletions packages/react/src/menu/styles.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { sx } from '@tonic-ui/styled-system';
import { useColorMode } from '../color-mode';
import { useColorStyle } from '../color-style';
import { useTheme } from '../theme';

const useMenuStyle = () => {
return {
Expand Down Expand Up @@ -96,7 +95,6 @@ const useMenuGroupStyle = () => {
};

const useMenuItemStyle = ({ tabIndex }) => {
const { colors, sizes } = useTheme();
const [colorMode] = useColorMode();
const color = {
dark: 'white:primary',
Expand All @@ -106,7 +104,7 @@ const useMenuItemStyle = ({ tabIndex }) => {
dark: 'rgba(255, 255, 255, 0.12)',
light: 'rgba(0, 0, 0, 0.12)',
}[colorMode];
const focusBoxShadowColor = {
const focusVisibleOutlineColor = {
dark: 'blue:60',
light: 'blue:60',
}[colorMode];
Expand Down Expand Up @@ -134,7 +132,10 @@ const useMenuItemStyle = ({ tabIndex }) => {
userSelect: 'none',
width: '100%',
_focusVisible: {
boxShadow: `inset 0 0 0 ${sizes?.['1h']} ${colors?.[focusBoxShadowColor]}`,
outlineColor: focusVisibleOutlineColor,
outlineOffset: '-1h',
outlineStyle: 'solid',
outlineWidth: '1h',
},
_hover: {
backgroundColor: hoverBackgroundColor,
Expand Down
6 changes: 4 additions & 2 deletions packages/react/src/radio/RadioControlBox.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ const RadioControlBox = forwardRef((
const checkedAndDisabledBorderColor = disabledBorderColor;

// focus color
const focusOutlineColor = {
const focusVisibleOutlineColor = {
dark: `${variantColor}:60`,
light: `${variantColor}:60`,
}[colorMode];
Expand All @@ -83,7 +83,9 @@ const RadioControlBox = forwardRef((
borderColor: hoverBorderColor,
},
[getRadioControlBoxSelector(':focus-visible')]: {
boxShadow: `0 0 0 2px ${theme?.colors?.[focusOutlineColor]}`,
outlineColor: focusVisibleOutlineColor,
outlineStyle: 'solid',
outlineWidth: '1h',
},
[getRadioControlBoxSelector(':disabled')]: {
borderColor: disabledBorderColor,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,9 @@ input[type="radio"]:hover+.emotion-4 {
}
input[type="radio"]:focus-visible+.emotion-4 {
box-shadow: 0 0 0 2px #1e5ede;
outline-color: var(--tonic-colors-blue-60);
outline-style: solid;
outline-width: var(--tonic-sizes-1h);
}
input[type="radio"]:disabled+.emotion-4 {
Expand Down Expand Up @@ -150,7 +152,9 @@ input[type="radio"]:hover+.emotion-14 {
}
input[type="radio"]:focus-visible+.emotion-14 {
box-shadow: 0 0 0 2px #1e5ede;
outline-color: var(--tonic-colors-blue-60);
outline-style: solid;
outline-width: var(--tonic-sizes-1h);
}
input[type="radio"]:disabled+.emotion-14 {
Expand Down Expand Up @@ -225,7 +229,9 @@ input[type="radio"]:hover+.emotion-24 {
}
input[type="radio"]:focus-visible+.emotion-24 {
box-shadow: 0 0 0 2px #1e5ede;
outline-color: var(--tonic-colors-blue-60);
outline-style: solid;
outline-width: var(--tonic-sizes-1h);
}
input[type="radio"]:disabled+.emotion-24 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,9 @@ exports[`Tabs should render correctly 1`] = `
.emotion-4:focus-visible {
outline-color: var(--tonic-colors-blue-60);
outline-width: var(--tonic-sizes-1h);
outline-style: solid;
outline-offset: calc(var(--tonic-space-1h) * -1);
outline-style: solid;
outline-width: var(--tonic-sizes-1h);
color: var(--tonic-colors-white-primary);
}
Expand Down Expand Up @@ -106,9 +106,9 @@ exports[`Tabs should render correctly 1`] = `
.emotion-6:focus-visible {
outline-color: var(--tonic-colors-blue-60);
outline-width: var(--tonic-sizes-1h);
outline-style: solid;
outline-offset: calc(var(--tonic-space-1h) * -1);
outline-style: solid;
outline-width: var(--tonic-sizes-1h);
color: var(--tonic-colors-white-primary);
}
Expand Down Expand Up @@ -160,9 +160,9 @@ exports[`Tabs should render correctly 1`] = `
.emotion-8:focus-visible {
outline-color: var(--tonic-colors-blue-60);
outline-width: var(--tonic-sizes-1h);
outline-style: solid;
outline-offset: calc(var(--tonic-space-1h) * -1);
outline-style: solid;
outline-width: var(--tonic-sizes-1h);
color: var(--tonic-colors-white-disabled);
}
Expand Down
12 changes: 6 additions & 6 deletions packages/react/src/tabs/styles.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ const useTabStyle = ({
if (variant === 'default') {
// border color
const disabledBorderColor = 'transparent';
const focusVisibleBorderColor = {
const focusVisibleOutlineColor = {
dark: 'blue:60',
light: 'blue:60',
}[colorMode];
Expand Down Expand Up @@ -141,10 +141,10 @@ const useTabStyle = ({
color: getColorStyleWithFallback(hoverColor),
},
_focusVisible: {
outlineColor: focusVisibleBorderColor,
outlineWidth: '1h',
outlineStyle: 'solid',
outlineColor: focusVisibleOutlineColor,
outlineOffset: '-1h',
outlineStyle: 'solid',
outlineWidth: '1h',
color: getColorStyleWithFallback(focusColor),
},
_selected: {
Expand Down Expand Up @@ -188,7 +188,7 @@ const useTabStyle = ({
dark: 'gray:80',
light: 'gray:20',
}[colorMode];
const focusVisibleBorderColor = {
const focusVisibleOutlineColor = {
dark: 'blue:60',
light: 'blue:60',
}[colorMode];
Expand Down Expand Up @@ -328,7 +328,7 @@ const useTabStyle = ({
_focusVisible: {
backgroundColor: getBackgroundColorStyleWithFallback(focusBackgroundColor),
color: getColorStyleWithFallback(focusColor),
outlineColor: focusVisibleBorderColor,
outlineColor: focusVisibleOutlineColor,
outlineWidth: '1h',
outlineStyle: 'solid',
outlineOffset: '-1h',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,10 @@ exports[`Tree should render correctly 1`] = `
}
.emotion-4:focus-visible {
box-shadow: inset 0 0 0 .125rem #1e5ede;
outline-color: var(--tonic-colors-blue-60);
outline-offset: calc(var(--tonic-space-1h) * -1);
outline-style: solid;
outline-width: var(--tonic-sizes-1h);
}
.emotion-4:hover,
Expand Down
9 changes: 5 additions & 4 deletions packages/react/src/tree/styles.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { useColorMode } from '../color-mode';
import { useTheme } from '../theme';

const useTreeItemStyle = () => {
return {
Expand All @@ -11,7 +10,6 @@ const useTreeItemContentStyle = ({
isSelected,
tabIndex,
}) => {
const { colors, sizes } = useTheme();
const [colorMode] = useColorMode();
const color = {
dark: 'white:primary',
Expand All @@ -21,7 +19,7 @@ const useTreeItemContentStyle = ({
dark: 'rgba(255, 255, 255, 0.12)',
light: 'rgba(0, 0, 0, 0.12)',
}[colorMode];
const focusBoxShadowColor = {
const focusVisibleOutlineColor = {
dark: 'blue:60',
light: 'blue:60',
}[colorMode];
Expand Down Expand Up @@ -51,7 +49,10 @@ const useTreeItemContentStyle = ({
backgroundColor: !isDisabled ? hoverBackgroundColor : undefined,
},
_focusVisible: {
boxShadow: `inset 0 0 0 ${sizes?.['1h']} ${colors?.[focusBoxShadowColor]}`,
outlineColor: focusVisibleOutlineColor,
outlineOffset: '-1h',
outlineStyle: 'solid',
outlineWidth: '1h',
},
};
};
Expand Down

0 comments on commit 280c405

Please sign in to comment.