Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix disabled Checkbox focus appearance #1321

Merged
merged 2 commits into from
Oct 4, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 6 additions & 7 deletions lib/src/checkbox/Checkbox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,7 @@ const DxcCheckbox = ({
const translatedLabels = useTranslatedLabels();

const handleCheckboxChange = () => {
if (document.activeElement !== checkboxRef?.current && tabIndex > -1)
checkboxRef?.current?.focus();

document.activeElement !== checkboxRef?.current && checkboxRef?.current?.focus();
const newChecked = checked ?? innerChecked;
checked ?? setInnerChecked((innerChecked) => !innerChecked);
onChange?.(!newChecked);
Expand Down Expand Up @@ -68,7 +66,7 @@ const DxcCheckbox = ({
{label && labelPosition === "before" && (
<LabelContainer id={labelId} disabled={disabled} backgroundType={backgroundType}>
{label}
{optional && <>{` ${translatedLabels.formFields.optionalLabel}`}</>}
{optional && ` ${translatedLabels.formFields.optionalLabel}`}
</LabelContainer>
)}
<ValueInput
Expand Down Expand Up @@ -99,7 +97,7 @@ const DxcCheckbox = ({
</CheckboxContainer>
{label && labelPosition === "after" && (
<LabelContainer id={labelId} disabled={disabled} backgroundType={backgroundType}>
{optional && <>{`${translatedLabels.formFields.optionalLabel} `}</>}
{optional && `${translatedLabels.formFields.optionalLabel} `}
{label}
</LabelContainer>
)}
Expand Down Expand Up @@ -208,9 +206,9 @@ const Checkbox = styled.span<CheckboxInputPropsType>`
justify-content: center;
height: 18px;
width: 18px;
border-radius: 2px;
border: solid 2px
${(props) => (props.disabled ? getDisabledColor(props, "border") : getNotDisabledColor(props, "border"))};
border-radius: 2px;
background-color: ${(props) =>
props.checked
? props.disabled
Expand All @@ -230,6 +228,7 @@ const Checkbox = styled.span<CheckboxInputPropsType>`
width: 22px;
height: 22px;
}
${(props) => props.disabled && "pointer-events: none;"}
`;

type MainContainerPropsType = {
Expand Down Expand Up @@ -270,4 +269,4 @@ const MainContainer = styled.div<MainContainerPropsType>`
}
`;

export default DxcCheckbox;
export default DxcCheckbox;