Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(combobox, input-time-zone): improve readOnly behavior and styling #9222

Merged
merged 2 commits into from
Apr 30, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 11 additions & 12 deletions packages/calcite-components/src/components/combobox/combobox.e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2004,21 +2004,20 @@ describe("calcite-combobox", () => {
});

it("prevents opening a readonly combobox", async () => {
const page = await newE2EPage({
html: html`
<calcite-combobox id="myCombobox" read-only="true">
<calcite-combobox-item value="Raising Arizona" text-label="Raising Arizona"></calcite-combobox-item>
<calcite-combobox-item value="Miller's Crossing" text-label="Miller's Crossing"></calcite-combobox-item>
<calcite-combobox-item value="The Hudsucker Proxy" text-label="The Hudsucker Proxy"></calcite-combobox-item>
<calcite-combobox-item value="Inside Llewyn Davis" text-label="Inside Llewyn Davis"></calcite-combobox-item>
</calcite-combobox>
`,
});
const page = await newE2EPage();
await page.setContent(html`
<calcite-combobox id="myCombobox" read-only>
<calcite-combobox-item value="Raising Arizona" text-label="Raising Arizona"></calcite-combobox-item>
<calcite-combobox-item value="Miller's Crossing" text-label="Miller's Crossing"></calcite-combobox-item>
<calcite-combobox-item value="The Hudsucker Proxy" text-label="The Hudsucker Proxy"></calcite-combobox-item>
<calcite-combobox-item value="Inside Llewyn Davis" text-label="Inside Llewyn Davis"></calcite-combobox-item>
</calcite-combobox>
`);

const combobox = await page.find("calcite-combobox");
expect(await combobox.getProperty("open")).toBeFalsy();
await combobox.click();
await page.waitForChanges();
expect(await combobox.getProperty("open")).toBeFalsy();

expect(await combobox.getProperty("open")).toBe(false);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,12 @@
@apply focus-inset;
}

:host([read-only]) {
.wrapper {
@apply bg-background font-medium;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Q: can we use tokens here instead?

}
}

:host([status="invalid"]) .wrapper {
@apply border-color-danger;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -806,3 +806,36 @@ export const validationMessageInAllScales_TestOnly = (): string => html`
</calcite-combobox>
</div>
`;

export const readOnlyAllModes = (): string => html`
<h1>read-only</h1>

<h2>single</h2>
<calcite-combobox read-only selection-mode="single">
<calcite-combobox-item value="one" text-label="one" selected></calcite-combobox-item>
<calcite-combobox-item value="two" text-label="two"></calcite-combobox-item>
<calcite-combobox-item value="three" text-label="three"></calcite-combobox-item>
</calcite-combobox>

<h2>single-persist</h2>
<calcite-combobox read-only selection-mode="single-persist">
<calcite-combobox-item value="one" text-label="one" selected></calcite-combobox-item>
<calcite-combobox-item value="two" text-label="two"></calcite-combobox-item>
<calcite-combobox-item value="three" text-label="three"></calcite-combobox-item>
</calcite-combobox>

<h2>multiple</h2>
<calcite-combobox read-only selection-mode="multiple">
<calcite-combobox-item value="one" text-label="one" selected></calcite-combobox-item>
<calcite-combobox-item value="two" text-label="two" selected></calcite-combobox-item>
<calcite-combobox-item value="three" text-label="three"></calcite-combobox-item>
</calcite-combobox>

<h2>ancestors</h2>
<calcite-combobox read-only selection-mode="ancestors">
<calcite-combobox-item value="parent" text-label="parent">
<calcite-combobox-item value="child1" text-label="child1"></calcite-combobox-item>
<calcite-combobox-item selected value="child2" text-label="child2"></calcite-combobox-item>
</calcite-combobox-item>
</calcite-combobox>
`;
14 changes: 10 additions & 4 deletions packages/calcite-components/src/components/combobox/combobox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -635,6 +635,10 @@ export class Combobox
}

private keyDownHandler = (event: KeyboardEvent): void => {
if (this.readOnly) {
return;
}

const { key } = event;

switch (key) {
Expand Down Expand Up @@ -1360,7 +1364,7 @@ export class Combobox
return (
<calcite-chip
class={chipClasses}
closable
closable={!this.readOnly}
icon={item.icon}
iconFlipRtl={item.iconFlipRtl}
id={item.guid ? `${chipUidPrefix}${item.guid}` : null}
Expand Down Expand Up @@ -1579,6 +1583,7 @@ export class Combobox
onFocus={this.comboboxFocusHandler}
onInput={this.inputHandler}
placeholder={placeholder}
readOnly={this.readOnly}
role="combobox"
type="text"
// 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)
Expand Down Expand Up @@ -1665,12 +1670,13 @@ export class Combobox
}

render(): VNode {
const { selectionDisplay, guid, label, open } = this;
const { selectionDisplay, guid, label, open, readOnly } = this;
const singleSelectionMode = isSingleLike(this.selectionMode);
const allSelectionDisplay = selectionDisplay === "all";
const singleSelectionDisplay = selectionDisplay === "single";
const fitSelectionDisplay = !singleSelectionMode && selectionDisplay === "fit";
const isClearable = !this.clearDisabled && this.value?.length > 0;

return (
<Host onClick={this.comboboxFocusHandler}>
<InteractiveContainer disabled={this.disabled}>
Expand Down Expand Up @@ -1714,15 +1720,15 @@ export class Combobox
</label>
{this.renderInput()}
</div>
{isClearable ? (
{!readOnly && isClearable ? (
<XButton
disabled={this.disabled}
key="close-button"
label={this.messages.clear}
scale={this.scale}
/>
) : null}
{this.renderChevronIcon()}
{!readOnly && this.renderChevronIcon()}
</div>
<ul
aria-labelledby={`${labelUidPrefix}${guid}`}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,3 +109,5 @@ export const validationMessageAllScales_TestOnly = (): string => html`
></calcite-input-time-zone>
</div>
`;

export const readOnly = (): string => html` <calcite-input-time-zone read-only></calcite-input-time-zone> `;
Loading