Skip to content

Open source website builder and Webflow alternative. Webstudio is an advanced visual builder that connects to any headless CMS, supports all CSS properties, and can be hosted anywhere, including with us.

Fix toggle group focus interfere, show error in storybook (#1923)

Ivan Starkov0c23cf580a45
diff --git a/packages/design-system/src/components/icon-button.tsx b/packages/design-system/src/components/icon-button.tsx
index 21af24f97e..81e3f29bd9 100644
--- a/packages/design-system/src/components/icon-button.tsx
+++ b/packages/design-system/src/components/icon-button.tsx
@@ -27,6 +27,7 @@ export const IconButton = styled("button", {
"&[data-focused=true], &:focus-visible": {
outline: `2px solid ${theme.colors.borderFocus}`,
+ outlineOffset: -2,
},
"&:disabled": {
@@ -40,7 +41,7 @@ export const IconButton = styled("button", {
borderColor: "transparent",
backgroundColor: theme.colors.backgroundActive,
color: theme.colors.foregroundContrastMain,
- "&:hover": {
+ "&:hover, &[data-hovered=true]": {
borderColor: "transparent",
backgroundColor: theme.colors.backgroundActive,
color: theme.colors.foregroundContrastMain,
@@ -51,7 +52,7 @@ export const IconButton = styled("button", {
variant: {
default: {
color: theme.colors.foregroundMain,
- "&:hover": {
+ "&:hover, &[data-hovered=true]": {
backgroundColor: theme.colors.backgroundHover,
},
// According to the design https://www.figma.com/file/sfCE7iLS0k25qCxiifQNLE/%F0%9F%93%9A-Webstudio-Library?node-id=4-3199&t=lpT9jFuaiUnz1Foa-0
@@ -61,7 +62,7 @@ export const IconButton = styled("button", {
backgroundColor: theme.colors.backgroundPresetMain,
borderColor: theme.colors.borderMain,
- "&:hover": {
+ "&:hover, &[data-hovered=true]": {
backgroundColor: theme.colors.backgroundHover,
},
},
@@ -75,7 +76,7 @@ export const IconButton = styled("button", {
backgroundColor: theme.colors.backgroundPresetMain,
borderColor: theme.colors.borderMain,
color: theme.colors.foregroundMain,
- "&:hover": {
+ "&:hover, &[data-hovered=true]": {
backgroundColor: theme.colors.backgroundPresetHover,
},
"&:disabled": {
@@ -87,7 +88,7 @@ export const IconButton = styled("button", {
backgroundColor: theme.colors.backgroundLocalMain,
borderColor: theme.colors.borderLocalMain,
color: theme.colors.foregroundLocalMain,
- "&:hover": {
+ "&:hover, &[data-hovered=true]": {
backgroundColor: theme.colors.backgroundLocalHover,
},
"&:disabled": {
@@ -99,7 +100,7 @@ export const IconButton = styled("button", {
backgroundColor: theme.colors.backgroundOverwrittenMain,
borderColor: theme.colors.borderOverwrittenMain,
color: theme.colors.foregroundOverwrittenMain,
- "&:hover": {
+ "&:hover, &[data-hovered=true]": {
backgroundColor: theme.colors.backgroundOverwrittenHover,
},
"&:disabled": {
@@ -111,7 +112,7 @@ export const IconButton = styled("button", {
backgroundColor: theme.colors.backgroundRemoteMain,
borderColor: theme.colors.borderRemoteMain,
color: theme.colors.foregroundRemoteMain,
- "&:hover": {
+ "&:hover, &[data-hovered=true]": {
backgroundColor: theme.colors.backgroundRemoteHover,
},
"&:disabled": {
diff --git a/packages/design-system/src/components/toggle-group.stories.tsx b/packages/design-system/src/components/toggle-group.stories.tsx
index a7e7e36bd3..7e0d85d925 100644
--- a/packages/design-system/src/components/toggle-group.stories.tsx
+++ b/packages/design-system/src/components/toggle-group.stories.tsx
@@ -18,16 +18,21 @@ const ToggleGroupButtons = () => {
<ToggleGroupButton value="one">
<BorderRadiusIndividualIcon fill="currentColor" />
</ToggleGroupButton>
- <ToggleGroupButton value="two">
+ <ToggleGroupButton value="two" data-focused={true}>
<BorderRadiusIndividualIcon fill="currentColor" />
</ToggleGroupButton>
- <ToggleGroupButton value="three">
+ <ToggleGroupButton value="three" data-hovered={true}>
<BorderRadiusIndividualIcon fill="currentColor" />
</ToggleGroupButton>
<ToggleGroupButton value="four">
<BorderRadiusIndividualIcon fill="currentColor" />
</ToggleGroupButton>
- <ToggleGroupButton value="five">
+ <ToggleGroupButton
+ value="five"
+ data-hovered={true}
+ data-focused={true}
+ aria-checked={true}
+ >
<BorderRadiusIndividualIcon fill="currentColor" />
</ToggleGroupButton>
<ToggleGroupButton value="six">
diff --git a/packages/design-system/src/components/toggle-group.tsx b/packages/design-system/src/components/toggle-group.tsx
index f4a6f1cf18..d713381c0d 100644
--- a/packages/design-system/src/components/toggle-group.tsx
+++ b/packages/design-system/src/components/toggle-group.tsx
@@ -61,13 +61,20 @@ export const ToggleGroup = styled(BaseToggleGroup, {
borderRadius: theme.borderRadius[4],
});
+const IconButtonStyled = styled(IconButton, {
+ "&[data-focused=true], &:focus-visible": {
+ // To not overlap focus-ring by the next button
+ zIndex: 0,
+ },
+});
+
const BaseToggleGroupButton = forwardRef<
ElementRef<"button">,
ComponentProps<typeof IconButton>
>((props, ref) => {
const { color } = useContext(ToggleGroupContext);
return (
- <IconButton
+ <IconButtonStyled
ref={ref}
{...props}
variant={
@@ -83,9 +90,6 @@ const BaseToggleGroupButton = forwardRef<
width: "auto",
height: theme.spacing[11],
minWidth: theme.spacing[11],
- // accept only 16px icons or text
- paddingLeft: theme.spacing[3],
- paddingRight: theme.spacing[3],
borderRadius: theme.borderRadius[2],
...textVariants.labelsTitleCase,
}}