Skip to content

Commit c8100be

Browse files
[Bug] Radio checked + focus state fixes (#2314)
* use border instead of pseudo element * Stylelint auto-fixes * Create rude-ears-tie.md Co-authored-by: Actions Auto Build <actions@github.com>
1 parent 12355f8 commit c8100be

File tree

2 files changed

+36
-41
lines changed

2 files changed

+36
-41
lines changed

.changeset/rude-ears-tie.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@primer/css": patch
3+
---
4+
5+
[Bug] Radio checked + focus state fixes

src/forms/FormControl.scss

Lines changed: 31 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@
7777
}
7878

7979
// default focus state
80-
&:focus-visible {
80+
&:not([type='checkbox']):not([type='radio']):focus-visible {
8181
@include focusBoxShadowInset;
8282
}
8383
}
@@ -520,8 +520,7 @@
520520

521521
// these selectors are temporary to override base.scss
522522
// once Field styles are widely adopted, we can adjust this and the global base styles
523-
input[type='checkbox'].FormControl-checkbox,
524-
input[type='radio'].FormControl-radio {
523+
input[type='checkbox'].FormControl-checkbox {
525524
@include Field;
526525

527526
position: relative;
@@ -604,9 +603,8 @@ input[type='radio'].FormControl-radio {
604603
// stylelint-enable primer/colors
605604
}
606605

607-
&:focus,
608606
&:focus-visible {
609-
outline-offset: 2px;
607+
@include focusOutline(2px);
610608
}
611609

612610
&:indeterminate {
@@ -618,31 +616,43 @@ input[type='radio'].FormControl-radio {
618616
}
619617

620618
input[type='radio'].FormControl-radio {
621-
border-radius: var(--primer-borderRadius-full, 100vh);
619+
@include Field;
622620

623-
&::before {
624-
clip-path: circle(0%);
625-
mask-image: url('data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMTAiIGhlaWdodD0iMTAiIHZpZXdCb3g9IjAgMCAxMCAxMCIgZmlsbD0ibm9uZSIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIj4KPHBhdGggZD0iTTUgOS4zNzVDNy40MTYyMiA5LjM3NSA5LjM3NSA3LjQxNjIyIDkuMzc1IDVDOS4zNzUgMi41ODM3NiA3LjQxNjIyIDAuNjI1IDUgMC42MjVDMi41ODM3NiAwLjYyNSAwLjYyNSAyLjU4Mzc2IDAuNjI1IDVDMC42MjUgNy40MTYyMiAyLjU4Mzc2IDkuMzc1IDUgOS4zNzVaIiBmaWxsPSJ3aGl0ZSIvPgo8L3N2Zz4K'); // checked circle image
626-
mask-size: 65%;
621+
position: relative;
622+
width: var(--base-size-16, 16px);
623+
height: var(--base-size-16, 16px);
624+
margin: 0;
625+
margin-top: 0.125rem; // 2px to center align with label (20px line-height)
626+
cursor: pointer;
627+
border-radius: var(--primer-borderRadius-full, 100vh);
628+
transition: background-color, border-color 80ms cubic-bezier(0.33, 1, 0.68, 1); // checked -> unchecked - add 120ms delay to fully see animation-out
629+
appearance: none;
627630

628-
@media screen and (prefers-reduced-motion: no-preference) {
629-
animation: radioOut 80ms cubic-bezier(0.65, 0, 0.35, 1) forwards; // slightly snappier animation out
630-
}
631+
&::after {
632+
@include minTouchTarget(var(--primer-control-medium-size, 32px), var(--primer-control-medium-size, 32px));
631633
}
632634

633635
&:checked {
634-
&::before {
635-
@media screen and (prefers-reduced-motion: no-preference) {
636-
animation: radioIn 80ms cubic-bezier(0.65, 0, 0.35, 1) forwards 80ms;
637-
}
636+
border-color: var(--color-accent-fg);
637+
border-width: var(--base-size-4, 4px);
638+
639+
&:disabled {
640+
cursor: not-allowed;
641+
border-color: var(--color-primer-fg-disabled);
638642
}
639643
}
640644

641-
&:indeterminate {
642-
&::before {
643-
visibility: hidden;
644-
}
645+
&:focus-visible {
646+
@include focusOutline(2px);
647+
}
648+
649+
// Windows High Contrast mode
650+
// stylelint-disable primer/colors
651+
@media (forced-colors: active) {
652+
background-color: CanvasText;
653+
border-color: CanvasText;
645654
}
655+
// stylelint-enable primer/colors
646656
}
647657

648658
@keyframes checkmarkIn {
@@ -664,23 +674,3 @@ input[type='radio'].FormControl-radio {
664674
clip-path: inset(var(--base-size-16, 16px) 0 0 0);
665675
}
666676
}
667-
668-
@keyframes radioIn {
669-
from {
670-
clip-path: circle(0%);
671-
}
672-
673-
to {
674-
clip-path: circle(100%);
675-
}
676-
}
677-
678-
@keyframes radioOut {
679-
from {
680-
clip-path: circle(100%);
681-
}
682-
683-
to {
684-
clip-path: circle(0%);
685-
}
686-
}

0 commit comments

Comments
 (0)