Skip to content

Commit 606d80f

Browse files
authored
fix(combobox, input-time-zone): improve readOnly behavior and styling (#9222)
**Related Issue:** #7853 #8666 ## Summary Improves read-only behavior in combobox and applies proper styling.
1 parent b1ba428 commit 606d80f

File tree

5 files changed

+69
-17
lines changed

5 files changed

+69
-17
lines changed

packages/calcite-components/src/components/combobox/combobox.e2e.ts

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2004,21 +2004,20 @@ describe("calcite-combobox", () => {
20042004
});
20052005

20062006
it("prevents opening a readonly combobox", async () => {
2007-
const page = await newE2EPage({
2008-
html: html`
2009-
<calcite-combobox id="myCombobox" read-only="true">
2010-
<calcite-combobox-item value="Raising Arizona" text-label="Raising Arizona"></calcite-combobox-item>
2011-
<calcite-combobox-item value="Miller's Crossing" text-label="Miller's Crossing"></calcite-combobox-item>
2012-
<calcite-combobox-item value="The Hudsucker Proxy" text-label="The Hudsucker Proxy"></calcite-combobox-item>
2013-
<calcite-combobox-item value="Inside Llewyn Davis" text-label="Inside Llewyn Davis"></calcite-combobox-item>
2014-
</calcite-combobox>
2015-
`,
2016-
});
2007+
const page = await newE2EPage();
2008+
await page.setContent(html`
2009+
<calcite-combobox id="myCombobox" read-only>
2010+
<calcite-combobox-item value="Raising Arizona" text-label="Raising Arizona"></calcite-combobox-item>
2011+
<calcite-combobox-item value="Miller's Crossing" text-label="Miller's Crossing"></calcite-combobox-item>
2012+
<calcite-combobox-item value="The Hudsucker Proxy" text-label="The Hudsucker Proxy"></calcite-combobox-item>
2013+
<calcite-combobox-item value="Inside Llewyn Davis" text-label="Inside Llewyn Davis"></calcite-combobox-item>
2014+
</calcite-combobox>
2015+
`);
20172016

20182017
const combobox = await page.find("calcite-combobox");
2019-
expect(await combobox.getProperty("open")).toBeFalsy();
20202018
await combobox.click();
20212019
await page.waitForChanges();
2022-
expect(await combobox.getProperty("open")).toBeFalsy();
2020+
2021+
expect(await combobox.getProperty("open")).toBe(false);
20232022
});
20242023
});

packages/calcite-components/src/components/combobox/combobox.scss

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,16 @@
7272
@apply focus-inset;
7373
}
7474

75+
:host([read-only]) {
76+
.wrapper {
77+
background-color: var(--calcite-color-background);
78+
}
79+
80+
.label {
81+
font-weight: var(--calcite-font-weight-medium);
82+
}
83+
}
84+
7585
:host([status="invalid"]) .wrapper {
7686
@apply border-color-danger;
7787
}

packages/calcite-components/src/components/combobox/combobox.stories.ts

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -806,3 +806,36 @@ export const validationMessageInAllScales_TestOnly = (): string => html`
806806
</calcite-combobox>
807807
</div>
808808
`;
809+
810+
export const readOnlyAllModes = (): string => html`
811+
<h1>read-only</h1>
812+
813+
<h2>single</h2>
814+
<calcite-combobox read-only selection-mode="single">
815+
<calcite-combobox-item value="one" text-label="one" selected></calcite-combobox-item>
816+
<calcite-combobox-item value="two" text-label="two"></calcite-combobox-item>
817+
<calcite-combobox-item value="three" text-label="three"></calcite-combobox-item>
818+
</calcite-combobox>
819+
820+
<h2>single-persist</h2>
821+
<calcite-combobox read-only selection-mode="single-persist">
822+
<calcite-combobox-item value="one" text-label="one" selected></calcite-combobox-item>
823+
<calcite-combobox-item value="two" text-label="two"></calcite-combobox-item>
824+
<calcite-combobox-item value="three" text-label="three"></calcite-combobox-item>
825+
</calcite-combobox>
826+
827+
<h2>multiple</h2>
828+
<calcite-combobox read-only selection-mode="multiple">
829+
<calcite-combobox-item value="one" text-label="one" selected></calcite-combobox-item>
830+
<calcite-combobox-item value="two" text-label="two" selected></calcite-combobox-item>
831+
<calcite-combobox-item value="three" text-label="three"></calcite-combobox-item>
832+
</calcite-combobox>
833+
834+
<h2>ancestors</h2>
835+
<calcite-combobox read-only selection-mode="ancestors">
836+
<calcite-combobox-item value="parent" text-label="parent">
837+
<calcite-combobox-item value="child1" text-label="child1"></calcite-combobox-item>
838+
<calcite-combobox-item selected value="child2" text-label="child2"></calcite-combobox-item>
839+
</calcite-combobox-item>
840+
</calcite-combobox>
841+
`;

packages/calcite-components/src/components/combobox/combobox.tsx

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -635,6 +635,10 @@ export class Combobox
635635
}
636636

637637
private keyDownHandler = (event: KeyboardEvent): void => {
638+
if (this.readOnly) {
639+
return;
640+
}
641+
638642
const { key } = event;
639643

640644
switch (key) {
@@ -1348,7 +1352,7 @@ export class Combobox
13481352
//--------------------------------------------------------------------------
13491353

13501354
renderChips(): VNode[] {
1351-
const { activeChipIndex, scale, selectionMode, messages } = this;
1355+
const { activeChipIndex, readOnly, scale, selectionMode, messages } = this;
13521356
return this.selectedItems.map((item, i) => {
13531357
const chipClasses = {
13541358
chip: true,
@@ -1357,10 +1361,12 @@ export class Combobox
13571361
const ancestors = [...getItemAncestors(item)].reverse();
13581362
const pathLabel = [...ancestors, item].map((el) => el.textLabel);
13591363
const label = selectionMode !== "ancestors" ? item.textLabel : pathLabel.join(" / ");
1364+
13601365
return (
13611366
<calcite-chip
1367+
appearance={readOnly ? "outline" : "solid"}
13621368
class={chipClasses}
1363-
closable
1369+
closable={!readOnly}
13641370
icon={item.icon}
13651371
iconFlipRtl={item.iconFlipRtl}
13661372
id={item.guid ? `${chipUidPrefix}${item.guid}` : null}
@@ -1579,6 +1585,7 @@ export class Combobox
15791585
onFocus={this.comboboxFocusHandler}
15801586
onInput={this.inputHandler}
15811587
placeholder={placeholder}
1588+
readOnly={this.readOnly}
15821589
role="combobox"
15831590
type="text"
15841591
// eslint-disable-next-line react/jsx-sort-props -- ref should be last so node attrs/props are in sync (see https://github.com/Esri/calcite-design-system/pull/6530)
@@ -1665,12 +1672,13 @@ export class Combobox
16651672
}
16661673

16671674
render(): VNode {
1668-
const { selectionDisplay, guid, label, open } = this;
1675+
const { selectionDisplay, guid, label, open, readOnly } = this;
16691676
const singleSelectionMode = isSingleLike(this.selectionMode);
16701677
const allSelectionDisplay = selectionDisplay === "all";
16711678
const singleSelectionDisplay = selectionDisplay === "single";
16721679
const fitSelectionDisplay = !singleSelectionMode && selectionDisplay === "fit";
16731680
const isClearable = !this.clearDisabled && this.value?.length > 0;
1681+
16741682
return (
16751683
<Host onClick={this.comboboxFocusHandler}>
16761684
<InteractiveContainer disabled={this.disabled}>
@@ -1714,15 +1722,15 @@ export class Combobox
17141722
</label>
17151723
{this.renderInput()}
17161724
</div>
1717-
{isClearable ? (
1725+
{!readOnly && isClearable ? (
17181726
<XButton
17191727
disabled={this.disabled}
17201728
key="close-button"
17211729
label={this.messages.clear}
17221730
scale={this.scale}
17231731
/>
17241732
) : null}
1725-
{this.renderChevronIcon()}
1733+
{!readOnly && this.renderChevronIcon()}
17261734
</div>
17271735
<ul
17281736
aria-labelledby={`${labelUidPrefix}${guid}`}

packages/calcite-components/src/components/input-time-zone/input-time-zone.stories.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,3 +109,5 @@ export const validationMessageAllScales_TestOnly = (): string => html`
109109
></calcite-input-time-zone>
110110
</div>
111111
`;
112+
113+
export const readOnly = (): string => html` <calcite-input-time-zone read-only></calcite-input-time-zone> `;

0 commit comments

Comments
 (0)