Skip to content
This repository has been archived by the owner on Aug 6, 2024. It is now read-only.

Commit

Permalink
Merge pull request #693 from appsmithorg/fix-radio-span-issue
Browse files Browse the repository at this point in the history
fix: Radio, Checkbox - child span issue
  • Loading branch information
albinAppsmith authored Jan 17, 2024
2 parents ba11fdd + e8d0e52 commit 9f01bd0
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 23 deletions.
5 changes: 5 additions & 0 deletions .changeset/few-shrimps-appear.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@appsmithorg/design-system": patch
---

fix: Radio, Checkbox - child span issue
1 change: 1 addition & 0 deletions packages/design-system/src/Checkbox/Checkbox.constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ import { CLASS_NAME_PREFIX } from "__config__/constants";

export const CheckboxClassName = `${CLASS_NAME_PREFIX}-checkbox`;
export const CheckboxClassNameLabel = `${CheckboxClassName}__label`;
export const CheckboxClassNameSquare = `${CheckboxClassName}__square`;
26 changes: 14 additions & 12 deletions packages/design-system/src/Checkbox/Checkbox.styles.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import styled, { css } from "styled-components";
import { CheckboxClassNameSquare } from "./Checkbox.constants";

const Variables = css`
/* This is a category level token.Since this is specific to checkbox, it is added here. */
Expand Down Expand Up @@ -34,7 +35,7 @@ const Checkbox = css`
cursor: pointer;
}
span {
span${"." + CheckboxClassNameSquare} {
position: absolute;
left: 0;
top: 0;
Expand All @@ -47,12 +48,12 @@ const Checkbox = css`
transition: background-color 200ms ease, border 200ms ease;
}
input[type="checkbox"]:checked + span {
input[type="checkbox"]:checked + span${"." + CheckboxClassNameSquare} {
--checkbox-color-border: var(--ads-v2-colors-control-field-checked-border);
--checkbox-color-background: var(--ads-v2-colors-control-field-checked-bg);
}
span::after {
span${"." + CheckboxClassNameSquare}::after {
content: "";
opacity: 0;
position: absolute;
Expand All @@ -66,11 +67,11 @@ const Checkbox = css`
z-index: 2;
}
input[type="checkbox"]:checked + span::after {
input[type="checkbox"]:checked + span${"." + CheckboxClassNameSquare}::after {
opacity: 1;
}
span::before {
span${"." + CheckboxClassNameSquare}::before {
content: "";
opacity: 0;
position: absolute;
Expand All @@ -84,7 +85,8 @@ const Checkbox = css`
z-index: 2;
}
input[type="checkbox"]:checked + span::before {
input[type="checkbox"]:checked
+ span${"." + CheckboxClassNameSquare}::before {
opacity: 1;
}
`;
Expand All @@ -102,7 +104,7 @@ export const StyledCheckbox = styled.label<{
${({ isIndeterminate }) => {
if (isIndeterminate) {
return css`
span {
span${"." + CheckboxClassNameSquare} {
--checkbox-color-border: var(
--ads-v2-colors-control-field-checked-border
);
Expand All @@ -111,15 +113,15 @@ export const StyledCheckbox = styled.label<{
);
}
span::after {
span${"." + CheckboxClassNameSquare}::after {
opacity: 1;
left: 2px;
top: 6px;
width: 10px;
transform: rotateZ(0deg);
}
span::before {
span${"." + CheckboxClassNameSquare}::before {
display: none;
}
`;
Expand All @@ -129,7 +131,7 @@ export const StyledCheckbox = styled.label<{
${({ isFocusVisible }) => {
if (isFocusVisible === true) {
return css`
span {
span${"." + CheckboxClassNameSquare} {
outline: var(--ads-v2-border-width-outline) solid
var(--ads-v2-color-outline);
outline-offset: var(--ads-v2-offset-outline);
Expand All @@ -150,7 +152,7 @@ export const StyledCheckbox = styled.label<{
} else {
return isChecked
? css`
&:hover > span {
&:hover > span${"." + CheckboxClassNameSquare} {
--checkbox-color-background: var(
--ads-v2-colors-control-field-checked-hover-bg
) !important;
Expand All @@ -160,7 +162,7 @@ export const StyledCheckbox = styled.label<{
}
`
: css`
&:hover > span {
&:hover > span${"." + CheckboxClassNameSquare} {
--checkbox-color-border: var(
--ads-v2-colors-control-field-hover-border
);
Expand Down
7 changes: 5 additions & 2 deletions packages/design-system/src/Checkbox/Checkbox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@ import clsx from "classnames";

import { CheckboxProps } from "./Checkbox.types";
import { StyledCheckbox } from "./Checkbox.styles";
import { CheckboxClassName } from "./Checkbox.constants";
import {
CheckboxClassName,
CheckboxClassNameSquare,
} from "./Checkbox.constants";

function Checkbox(props: CheckboxProps) {
const { children, className, isDisabled, isIndeterminate } = props;
Expand All @@ -26,7 +29,7 @@ function Checkbox(props: CheckboxProps) {
>
{children}
<input {...inputProps} {...focusProps} ref={ref} />
<span />
<span className={CheckboxClassNameSquare} />
</StyledCheckbox>
);
}
Expand Down
1 change: 1 addition & 0 deletions packages/design-system/src/Radio/Radio.constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@ import { CLASS_NAME_PREFIX } from "__config__/constants";

export const RadioClassName = `${CLASS_NAME_PREFIX}-radio`;
export const RadioLabelClassName = `${RadioClassName}__label`;
export const RadioDotClassName = `${RadioClassName}__dot`;

export const RadioGroupClassName = `${CLASS_NAME_PREFIX}-radio-group`;
18 changes: 11 additions & 7 deletions packages/design-system/src/Radio/Radio.styles.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import styled, { css } from "styled-components";
import { RadioDotClassName } from "./Radio.constants";

const Variables = css`
--ads-v2-colors-control-radio-dot-checked-bg: var(
Expand All @@ -25,7 +26,7 @@ const BasicStyles = css`
font-family: var(--ads-v2-font-family);
color: var(--radio-color-label);
span::before {
span${"." + RadioDotClassName}::before {
content: "";
position: absolute;
width: var(--ads-v2-spaces-5);
Expand All @@ -39,7 +40,7 @@ const BasicStyles = css`
transition: border-color 400ms ease;
}
span::after {
span${"." + RadioDotClassName}::after {
content: "";
position: absolute;
width: var(--ads-v2-spaces-5);
Expand All @@ -53,27 +54,30 @@ const BasicStyles = css`
transition: transform 200ms ease;
}
input[type="radio"]:checked + span::before {
input[type="radio"]:checked + span${"." + RadioDotClassName}::before {
--radio-color-border: var(--ads-v2-colors-control-field-checked-border);
}
input[type="radio"]:checked + span::after {
input[type="radio"]:checked + span${"." + RadioDotClassName}::after {
transform: translateY(-50%) scale(0.55);
}
/* unchecked hover - outer circle */
input[type="radio"]:hover:not(:disabled) + span::before {
input[type="radio"]:hover:not(:disabled)
+ span${"." + RadioDotClassName}::before {
--radio-color-border: var(--ads-v2-colors-control-field-hover-border);
}
/* checked hover - outer circle */
input[type="radio"]:checked:hover:not(:disabled) + span::before {
input[type="radio"]:checked:hover:not(:disabled)
+ span${"." + RadioDotClassName}::before {
--radio-color-border: var(
--ads-v2-colors-control-field-checked-hover-border
);
}
/* checked hover - inner circle */
input[type="radio"]:checked:hover:not(:disabled) + span::after {
input[type="radio"]:checked:hover:not(:disabled)
+ span${"." + RadioDotClassName}::after {
--radio-color-dot: var(--ads-v2-colors-control-radio-dot-checked-hover-bg);
}
`;
Expand Down
8 changes: 6 additions & 2 deletions packages/design-system/src/Radio/Radio.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@ import clsx from "classnames";

import { StyledRadio, StyledRadioGroup } from "./Radio.styles";
import { RadioProps, RadioGroupProps } from "./Radio.types";
import { RadioClassName, RadioGroupClassName } from "./Radio.constants";
import {
RadioClassName,
RadioDotClassName,
RadioGroupClassName,
} from "./Radio.constants";

const RadioContext = React.createContext({} as RadioGroupState);

Expand Down Expand Up @@ -43,7 +47,7 @@ export function Radio(props: RadioProps) {
>
{children}
<input {...inputProps} {...focusProps} ref={ref} />
<span />
<span className={RadioDotClassName} />
</StyledRadio>
);
}

0 comments on commit 9f01bd0

Please sign in to comment.