Skip to content

Commit 253db17

Browse files
committed
feat(combobox): refactor CSS and clean up syntax
1 parent 255e1b1 commit 253db17

File tree

5 files changed

+45
-52
lines changed

5 files changed

+45
-52
lines changed

.changeset/new-doors-fold.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22
"@spectrum-css/combobox": minor
33
---
44

5-
Adding read only state to combobox
5+
Combobox now includes a `read-only` state. Add the `is-readOnly` class to the Combobox to enable this feature.

components/combobox/index.css

Lines changed: 37 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,27 @@
220220
.spectrum-Popover.is-open {
221221
transform: translateY(var(--mod-combobox-spacing-edge-to-menu, var(--spectrum-combobox-spacing-edge-to-menu)));
222222
}
223+
224+
&.is-readOnly .spectrum-Combobox-textfield {
225+
input:read-only {
226+
background-color: var(--spectrum-combobox-readonly-input-background-color);
227+
border-color: var(--spectrum-combobox-readonly-input-border-color);
228+
229+
&:hover {
230+
background-color: revert;
231+
}
232+
}
233+
234+
&.is-invalid input:read-only {
235+
border-color: var(--highcontrast-textfield-border-color-invalid-default, var(--mod-textfield-border-color-invalid-default, var(--spectrum-combobox-readonly-border-color-invalid-default)));
236+
}
237+
238+
&.is-disabled input:read-only {
239+
background-color: var(--mod-textfield-background-color-disabled, var(--spectrum-combobox-readonly-background-color-disabled));
240+
border-color: transparent;
241+
color: var(--highcontrast-textfield-text-color-disabled, var(--mod-textfield-text-color-disabled, var(--spectrum-combobox-readonly-text-color-disabled)));
242+
}
243+
}
223244
}
224245

225246
/* LOADING INDICATOR */
@@ -321,8 +342,6 @@
321342
font-size: var(--mod-combobox-font-size, var(--spectrum-combobox-font-size));
322343
font-style: var(--mod-combobox-font-style, var(--spectrum-combobox-font-style));
323344

324-
325-
326345
&::placeholder {
327346
--mod-textfield-text-color-default: var(--mod-combobox-font-color-placeholder);
328347
}
@@ -378,49 +397,30 @@
378397
}
379398
}
380399

381-
/* Combobox Read-only */
382-
.spectrum-Textfield.is-readOnly {
383-
input:read-only {
384-
background-color: var(--spectrum-combobox-readonly-input-background-color);
385-
border-color: var(--spectrum-combobox-readonly-input-border-color);
386-
387-
&:hover {
388-
background-color: revert;
389-
border-color: revert;
390-
}
391-
}
392-
393-
&.is-invalid input:read-only {
394-
border-color: var(--highcontrast-textfield-border-color-invalid-default, var(--mod-textfield-border-color-invalid-default, var(--spectrum-combobox-readonly-border-color-invalid-default)));
395-
}
396-
397-
&.is-disabled input:read-only {
398-
background-color: var(--mod-textfield-background-color-disabled, var(--spectrum-combobox-readonly-background-color-disabled));
399-
border-color: transparent;
400-
color: var(--highcontrast-textfield-text-color-disabled, var(--mod-textfield-text-color-disabled, var(--spectrum-combobox-readonly-text-color-disabled)));
401-
}
402-
403-
&.spectrum-Textfield--quiet {
404-
input:read-only {
405-
background-color: unset;
406-
border-color: unset;
407-
}
408-
409-
&.is-invalid input:read-only {
410-
border-color: var(--highcontrast-textfield-border-color-invalid-default, var(--mod-textfield-border-color-invalid-default, var(--spectrum-combobox-readonly-border-color-invalid-default)));
411-
}
412-
}
413-
}
414-
415400
/* QUIET VARIATION (no visible background) */
416-
/* stylelint-disable-next-line no-duplicate-selectors -- Combobox quiet variation and mods */
417401
.spectrum-Combobox--quiet {
418402
border-radius: 0;
419403

420404
.spectrum-Combobox-textfield {
421405
&.is-invalid .spectrum-Textfield-validationIcon {
422406
inset-inline-end: var(--mod-combobox-button-width, var(--spectrum-combobox-button-width));
423407
}
408+
409+
&.spectrum-Textfield--quiet {
410+
input:read-only {
411+
background-color: unset;
412+
border-color: unset;
413+
}
414+
415+
input:read-only:hover {
416+
background-color: unset;
417+
border-color: unset;
418+
}
419+
420+
&.is-invalid input:read-only {
421+
border-color: var(--highcontrast-textfield-border-color-invalid-default, var(--mod-textfield-border-color-invalid-default, var(--spectrum-combobox-readonly-border-color-invalid-default)));
422+
}
423+
}
424424
}
425425

426426
.spectrum-Combobox-input {

components/combobox/metadata/metadata.json

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -70,12 +70,6 @@
7070
".spectrum-Textfield.is-disabled .spectrum-Textfield-validationIcon",
7171
".spectrum-Textfield.is-loading .spectrum-Textfield-validationIcon",
7272
".spectrum-Textfield.is-readOnly .spectrum-Textfield-validationIcon",
73-
".spectrum-Textfield.is-readOnly input:read-only",
74-
".spectrum-Textfield.is-readOnly input:read-only:hover",
75-
".spectrum-Textfield.is-readOnly.is-disabled input:read-only",
76-
".spectrum-Textfield.is-readOnly.is-invalid input:read-only",
77-
".spectrum-Textfield.is-readOnly.spectrum-Textfield--quiet input:read-only",
78-
".spectrum-Textfield.is-readOnly.spectrum-Textfield--quiet.is-invalid input:read-only",
7973
"[dir=\"rtl\"] .spectrum-Combobox-progress-circle"
8074
],
8175
"modifiers": [
@@ -287,8 +281,6 @@
287281
],
288282
"high-contrast": [
289283
"--highcontrast-combobox-border-color-highlight",
290-
"--highcontrast-combobox-border-color-invalid",
291-
"--highcontrast-textfield-border-color-invalid-default",
292-
"--highcontrast-textfield-text-color-disabled"
284+
"--highcontrast-combobox-border-color-invalid"
293285
]
294286
}

components/combobox/stories/combobox.test.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,6 @@ export const ComboBoxGroup = Variants({
4949
isQuiet: true,
5050
value: "United States of America and to the republic",
5151
},
52-
{
53-
testHeading: "Read-only",
54-
isReadOnly: true
55-
}
5652
],
5753
stateData: [
5854
{
@@ -75,5 +71,9 @@ export const ComboBoxGroup = Variants({
7571
testHeading: "Loading",
7672
isLoading: true,
7773
},
74+
{
75+
testHeading: "Read-only",
76+
isReadOnly: true
77+
},
7878
],
7979
});

components/combobox/stories/template.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ const Combobox = ({
4343
"is-keyboardFocused": !isDisabled && isKeyboardFocused,
4444
"is-loading": isLoading,
4545
"is-disabled": isDisabled,
46+
"is-readOnly": isReadOnly,
4647
...customClasses.reduce((a, c) => ({ ...a, [c]: true }), {}),
4748
})}
4849
id=${ifDefined(id)}
@@ -173,7 +174,7 @@ export const VariantGroup = (args, context) => {
173174
args: {...args, showFieldLabel: true, fieldLabelText: "Country"},
174175
},
175176
];
176-
177+
177178
return Container({
178179
direction: "row",
179180
withHeading: false,

0 commit comments

Comments
 (0)