Skip to content

Commit

Permalink
fix: move hover/focus hoisting into conditioning
Browse files Browse the repository at this point in the history
  • Loading branch information
Westbrook committed Mar 21, 2023
1 parent 7f66346 commit 15ac2f7
Show file tree
Hide file tree
Showing 9 changed files with 88 additions and 48 deletions.
4 changes: 2 additions & 2 deletions packages/checkbox/src/spectrum-checkbox.css
Original file line number Diff line number Diff line change
Expand Up @@ -409,7 +409,7 @@ governing permissions and limitations under the License.
);
}
:host([emphasized][invalid][invalid]:hover) #input:checked + #box:before,
:host([emphasized][invalid][invalid]:hover[indeterminate]) #box:before {
:host([emphasized][invalid][invalid][indeterminate]:hover) #box:before {
border-color: var(
--highcontrast-checkbox-color-hover,
var(
Expand All @@ -419,7 +419,7 @@ governing permissions and limitations under the License.
);
}
:host([emphasized]:hover) #input:checked + #box:before,
:host([emphasized]:hover[indeterminate]) #box:before {
:host([emphasized][indeterminate]:hover) #box:before {
border-color: var(
--highcontrast-checkbox-highlight-color-hover,
var(
Expand Down
12 changes: 6 additions & 6 deletions packages/dropzone/src/spectrum-dropzone.css
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,10 @@ governing permissions and limitations under the License.
border-style: dashed;
outline: 0;
}
:host(:focus.focus-visible) {
:host(.focus-visible:focus) {
border-style: solid;
}
:host(:focus:focus-visible) {
:host(:focus-visible:focus) {
border-style: solid;
}
:host {
Expand Down Expand Up @@ -71,21 +71,21 @@ governing permissions and limitations under the License.
rgb(var(--spectrum-global-color-static-gray-500-rgb))
);
}
:host(:focus.focus-visible) {
:host(.focus-visible:focus) {
border-color: var(
--spectrum-dropzone-border-color-selected-hover,
var(--spectrum-global-color-blue-400)
);
}
:host(:focus:focus-visible) {
:host(:focus-visible:focus) {
border-color: var(
--spectrum-dropzone-border-color-selected-hover,
var(--spectrum-global-color-blue-400)
);
}
:host(:focus[dragged].focus-visible) ::slotted(*) {
:host([dragged].focus-visible:focus) ::slotted(*) {
color: var(--spectrum-global-color-blue-400);
}
:host(:focus[dragged]:focus-visible) ::slotted(*) {
:host([dragged]:focus-visible:focus) ::slotted(*) {
color: var(--spectrum-global-color-blue-400);
}
44 changes: 44 additions & 0 deletions packages/number-field/src/spectrum-config.v2.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,50 @@ const config = {
fileName: 'number-field',
hoistCustomPropertiesFrom: 'spectrum-Stepper',
components: [
{
find: builder.pseudoClass('hover'),
replace: builder.pseudoClass('hover'),
hoist: true,
},
{
find: {
type: 'pseudo-class',
kind: 'not',
selectors: [[builder.class('is-focused')]],
},
replace: {
type: 'pseudo-class',
kind: 'not',
selectors: [[builder.attribute('focused')]],
},
hoist: true,
},
{
find: {
type: 'pseudo-class',
kind: 'not',
selectors: [[builder.class('is-disabled')]],
},
replace: {
type: 'pseudo-class',
kind: 'not',
selectors: [[builder.attribute('disabled')]],
},
hoist: true,
},
{
find: {
type: 'pseudo-class',
kind: 'not',
selectors: [[builder.class('is-invalid')]],
},
replace: {
type: 'pseudo-class',
kind: 'not',
selectors: [[builder.attribute('invalid')]],
},
hoist: true,
},
{
exactSelector: true,
find: [builder.class('spectrum-Stepper--quiet')],
Expand Down
12 changes: 6 additions & 6 deletions packages/number-field/src/spectrum-number-field.css
Original file line number Diff line number Diff line change
Expand Up @@ -249,14 +249,14 @@ governing permissions and limitations under the License.
position: absolute;
width: var(--spectrum-stepper-button-offset);
}
:host(:hover)
#textfield:not(.is-disabled):not(.is-invalid):not(.is-focused):not(.is-keyboardFocused)
:host(:hover:not([disabled]):not([invalid]):not([focused]))
#textfield:not(.is-keyboardFocused)
.input,
:host(:hover)
#textfield:not(.is-disabled):not(.is-invalid):not(.is-focused):not(.is-keyboardFocused)
:host(:hover:not([disabled]):not([invalid]):not([focused]))
#textfield:not(.is-keyboardFocused)
.stepDown,
:host(:hover)
#textfield:not(.is-disabled):not(.is-invalid):not(.is-focused):not(.is-keyboardFocused)
:host(:hover:not([disabled]):not([invalid]):not([focused]))
#textfield:not(.is-keyboardFocused)
.stepUp {
border-color: var(
--spectrum-textfield-m-texticon-border-color-hover,
Expand Down
8 changes: 4 additions & 4 deletions packages/radio/src/spectrum-radio.css
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ governing permissions and limitations under the License.
)
);
}
:host(:hover[checked]) #input + #button:before {
:host([checked]:hover) #input + #button:before {
border-color: var(
--highcontrast-radio-button-checked-border-color-hover,
var(
Expand Down Expand Up @@ -257,7 +257,7 @@ governing permissions and limitations under the License.
var(--spectrum-radio-focus-indicator-gap) * 2
);
}
:host(:focus[checked]) #input + #button:before {
:host([checked]:focus) #input + #button:before {
border-color: var(
--highcontrast-radio-button-checked-border-color-focus,
var(
Expand Down Expand Up @@ -310,7 +310,7 @@ governing permissions and limitations under the License.
)
);
}
:host([emphasized]:hover[checked]) #input + #button:before {
:host([emphasized][checked]:hover) #input + #button:before {
border-color: var(
--highcontrast-radio-emphasized-accent-color-hover,
var(
Expand All @@ -328,7 +328,7 @@ governing permissions and limitations under the License.
)
);
}
:host([emphasized]:focus[checked]) #input + #button:before {
:host([emphasized][checked]:focus) #input + #button:before {
border-color: var(
--highcontrast-radio-emphasized-accent-color-focus,
var(
Expand Down
36 changes: 18 additions & 18 deletions packages/switch/src/spectrum-switch.css
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,7 @@ governing permissions and limitations under the License.
)
);
}
:host(:hover[checked]) #input:enabled + #switch {
:host([checked]:hover) #input:enabled + #switch {
background-color: var(
--highcontrast-switch-background-color-selected-hover,
var(
Expand All @@ -395,7 +395,7 @@ governing permissions and limitations under the License.
)
);
}
:host(:hover[checked]) #input:enabled + #switch:before {
:host([checked]:hover) #input:enabled + #switch:before {
border-color: var(
--highcontrast-switch-handle-border-color-selected-hover,
var(
Expand All @@ -404,7 +404,7 @@ governing permissions and limitations under the License.
)
);
}
:host(:hover[disabled]) #input + #switch {
:host([disabled]:hover) #input + #switch {
background-color: var(
--highcontrast-switch-background-color-disabled,
var(
Expand All @@ -413,7 +413,7 @@ governing permissions and limitations under the License.
)
);
}
:host(:hover[disabled]) #input + #switch:before {
:host([disabled]:hover) #input + #switch:before {
border-color: var(
--highcontrast-switch-handle-border-color-disabled,
var(
Expand All @@ -422,7 +422,7 @@ governing permissions and limitations under the License.
)
);
}
:host(:hover[disabled]) #input ~ #label {
:host([disabled]:hover) #input ~ #label {
color: var(
--highcontrast-switch-label-color-disabled,
var(
Expand All @@ -431,7 +431,7 @@ governing permissions and limitations under the License.
)
);
}
:host(:hover[disabled][checked]) #input + #switch {
:host([disabled][checked]:hover) #input + #switch {
background-color: var(
--highcontrast-switch-background-color-selected-disabled,
var(
Expand All @@ -440,7 +440,7 @@ governing permissions and limitations under the License.
)
);
}
:host(:hover[disabled][checked]) #input + #switch:before {
:host([disabled][checked]:hover) #input + #switch:before {
border-color: var(
--highcontrast-switch-handle-border-color-disabled,
var(
Expand All @@ -449,7 +449,7 @@ governing permissions and limitations under the License.
)
);
}
:host(:hover[disabled][checked]) #input ~ #label {
:host([disabled][checked]:hover) #input ~ #label {
color: var(
--highcontrast-switch-label-color-disabled,
var(
Expand Down Expand Up @@ -544,8 +544,8 @@ governing permissions and limitations under the License.
)
);
}
:host(:hover[checked]) #input.focus-visible + #switch,
:host([checked]) #input.focus-visible + #switch {
:host([checked]) #input.focus-visible + #switch,
:host([checked]:hover) #input.focus-visible + #switch {
background-color: var(
--highcontrast-switch-background-color-selected-focus,
var(
Expand All @@ -554,8 +554,8 @@ governing permissions and limitations under the License.
)
);
}
:host(:hover[checked]) #input:focus-visible + #switch,
:host([checked]) #input:focus-visible + #switch {
:host([checked]) #input:focus-visible + #switch,
:host([checked]:hover) #input:focus-visible + #switch {
background-color: var(
--highcontrast-switch-background-color-selected-focus,
var(
Expand All @@ -564,8 +564,8 @@ governing permissions and limitations under the License.
)
);
}
:host(:hover[checked]) #input.focus-visible + #switch:before,
:host([checked]) #input.focus-visible + #switch:before {
:host([checked]) #input.focus-visible + #switch:before,
:host([checked]:hover) #input.focus-visible + #switch:before {
border-color: var(
--highcontrast-switch-handle-border-color-selected-focus,
var(
Expand All @@ -574,8 +574,8 @@ governing permissions and limitations under the License.
)
);
}
:host(:hover[checked]) #input:focus-visible + #switch:before,
:host([checked]) #input:focus-visible + #switch:before {
:host([checked]) #input:focus-visible + #switch:before,
:host([checked]:hover) #input:focus-visible + #switch:before {
border-color: var(
--highcontrast-switch-handle-border-color-selected-focus,
var(
Expand Down Expand Up @@ -708,11 +708,11 @@ governing permissions and limitations under the License.
:host(:hover) #input:not(:checked) + #switch {
box-shadow: inset 0 0 0 1px Highlight;
}
:host(:hover[disabled][checked]) #input + #switch {
:host([disabled][checked]:hover) #input + #switch {
background-color: GrayText;
box-shadow: inset 0 0 0 1px GrayText;
}
:host(:hover[disabled][checked]) #input + #switch:before {
:host([disabled][checked]:hover) #input + #switch:before {
background-color: ButtonFace;
border-color: GrayText;
}
Expand Down
2 changes: 1 addition & 1 deletion packages/tabs/src/spectrum-config.v2.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ const config = {
inPackage: '@spectrum-css/tabs',
outPackage: 'tabs',
fileName: 'tabs',
// hoistCustomPropertiesFrom: 'spectrum-Tabs',
components: [
{
exactSelector: true,
Expand Down Expand Up @@ -198,6 +197,7 @@ const config = {
excludeByComponents: [
builder.class('spectrum-Tabs-itemLabel'),
builder.class('spectrum-Icon'),
builder.pseudoClass('hover'),
],
excludeByExactComponentSeries: [
[builder.class('spectrum-Tabs-item')],
Expand Down
3 changes: 0 additions & 3 deletions packages/tabs/src/spectrum-tabs.css
Original file line number Diff line number Diff line change
Expand Up @@ -826,9 +826,6 @@ governing permissions and limitations under the License.
--spectrum-tabs-emphasized-texticon-tabitem-selection-indicator-background-color-selected
);
}
:host(:hover)::slotted(:not([slot])) {
color: var(--spectrum-tabs-textonly-tabitem-text-color-hover);
}
::slotted([selected]:not([slot])) {
color: var(--spectrum-tabs-textonly-tabitem-text-color-selected);
}
Expand Down
15 changes: 7 additions & 8 deletions tasks/process-spectrum.js
Original file line number Diff line number Diff line change
Expand Up @@ -206,14 +206,6 @@ async function processComponent(componentPath) {
},
});
matched = true;
} else if (isHoistedPseudoClass(component)) {
match.push({
hoist: true,
find: { ...component },
replace: { ...component },
});
matched = true;
log = true;
}
conversion.components.forEach((componentConversion) => {
if (Array.isArray(componentConversion.find)) {
Expand Down Expand Up @@ -413,6 +405,13 @@ async function processComponent(componentPath) {
});
// @ts-ignore
if (host) {
if (
newSelector.length &&
isHoistedPseudoClass(newSelector[0])
) {
host.selectors = host.selectors || [];
host.selectors?.push(newSelector.shift());
}
const firstIsPseudo = isPseudo(newSelector[0]);
const firstIsNotSlotted =
newSelector[0]?.value !== 'slotted';
Expand Down

0 comments on commit 15ac2f7

Please sign in to comment.