Skip to content

Commit

Permalink
fix(radio): process :focus and :focus-visible
Browse files Browse the repository at this point in the history
  • Loading branch information
Westbrook authored and najikahalsema committed Apr 3, 2023
1 parent 7b28309 commit 77bc0e9
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 5 deletions.
9 changes: 9 additions & 0 deletions packages/radio/src/spectrum-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,15 @@ const config = {
outPackage: 'radio',
fileName: 'radio',
components: [
{
find: [builder.pseudoClass('focus')],
replace: [
{
replace: builder.pseudoClass('focus-visible'),
hoist: true,
},
],
},
{
// .spectrum-Radio-input:focus-visible+.spectrum-Radio-button:after
find: [
Expand Down
68 changes: 63 additions & 5 deletions packages/radio/src/spectrum-radio.css
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ governing permissions and limitations under the License.
)
);
}
:host(:focus) #button:before {
:host(.focus-visible) #button:before {
border-color: var(
--highcontrast-radio-button-border-color-focus,
var(
Expand All @@ -235,7 +235,16 @@ governing permissions and limitations under the License.
)
);
}
:host(:focus) #button:after {
:host(:focus-visible) #button:before {
border-color: var(
--highcontrast-radio-button-border-color-focus,
var(
--mod-radio-button-border-color-focus,
var(--spectrum-radio-button-border-color-focus)
)
);
}
:host(.focus-visible) #button:after {
border-color: var(
--highcontrast-radio-focus-indicator-color,
var(
Expand All @@ -257,7 +266,29 @@ governing permissions and limitations under the License.
var(--spectrum-radio-focus-indicator-gap) * 2
);
}
:host([checked]:focus) #input + #button:before {
:host(:focus-visible) #button:after {
border-color: var(
--highcontrast-radio-focus-indicator-color,
var(
--mod-radio-focus-indicator-color,
var(--spectrum-radio-focus-indicator-color)
)
);
border-style: solid;
border-width: var(
--mod-radio-focus-indicator-thickness,
var(--spectrum-radio-focus-indicator-thickness)
);
height: calc(
var(--spectrum-radio-button-control-size) +
var(--spectrum-radio-focus-indicator-gap) * 2
);
width: calc(
var(--spectrum-radio-button-control-size) +
var(--spectrum-radio-focus-indicator-gap) * 2
);
}
:host(.focus-visible[checked]) #input + #button:before {
border-color: var(
--highcontrast-radio-button-checked-border-color-focus,
var(
Expand All @@ -266,7 +297,25 @@ governing permissions and limitations under the License.
)
);
}
:host(:focus) #label {
:host(:focus-visible[checked]) #input + #button:before {
border-color: var(
--highcontrast-radio-button-checked-border-color-focus,
var(
--mod-radio-button-checked-border-color-focus,
var(--spectrum-radio-button-checked-border-color-focus)
)
);
}
:host(.focus-visible) #label {
color: var(
--highcontrast-radio-neutral-content-color-focus,
var(
--mod-radio-neutral-content-color-focus,
var(--spectrum-radio-neutral-content-color-focus)
)
);
}
:host(:focus-visible) #label {
color: var(
--highcontrast-radio-neutral-content-color-focus,
var(
Expand Down Expand Up @@ -328,7 +377,16 @@ governing permissions and limitations under the License.
)
);
}
:host([emphasized][checked]:focus) #input + #button:before {
:host([emphasized].focus-visible[checked]) #input + #button:before {
border-color: var(
--highcontrast-radio-emphasized-accent-color-focus,
var(
--mod-radio-emphasized-accent-color-focus,
var(--spectrum-radio-emphasized-accent-color-focus)
)
);
}
:host([emphasized]:focus-visible[checked]) #input + #button:before {
border-color: var(
--highcontrast-radio-emphasized-accent-color-focus,
var(
Expand Down

0 comments on commit 77bc0e9

Please sign in to comment.