Skip to content

Commit 153a122

Browse files
authored
feat(input-time-zone): add readonly support (#9111)
**Related Issue:** #7853 ## Summary Added `readOnly` property to input-time-zone to match the UX of other readonly controls, such as input-date-picker.
1 parent 23aad2d commit 153a122

File tree

5 files changed

+65
-0
lines changed

5 files changed

+65
-0
lines changed

packages/calcite-components/src/components.d.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1083,6 +1083,10 @@ export namespace Components {
10831083
* When `true`, the icon will be flipped when the element direction is right-to-left (`"rtl"`).
10841084
*/
10851085
"placeholderIconFlipRtl": boolean;
1086+
/**
1087+
* When `true`, the component's value can be read, but controls are not accessible and the value cannot be modified.
1088+
*/
1089+
"readOnly": boolean;
10861090
/**
10871091
* Updates the position of the component.
10881092
* @param delayed Reposition the component after a delay
@@ -2597,6 +2601,10 @@ export namespace Components {
25972601
* Determines the type of positioning to use for the overlaid content. Using `"absolute"` will work for most cases. The component will be positioned inside of overflowing parent containers and will affect the container's layout. `"fixed"` should be used to escape an overflowing parent container, or when the reference element's `position` CSS property is `"fixed"`.
25982602
*/
25992603
"overlayPositioning": OverlayPositioning;
2604+
/**
2605+
* When `true`, the component's value can be read, but controls are not accessible and the value cannot be modified.
2606+
*/
2607+
"readOnly": boolean;
26002608
/**
26012609
* This `date` will be used as a reference to Daylight Savings Time when creating time zone item groups. It can be either a Date instance or a string in ISO format (`"YYYY-MM-DD"`, `"YYYY-MM-DDTHH:MM:SS.SSSZ"`).
26022610
* @see [Date.prototype.toISOString](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toISOString)
@@ -8529,6 +8537,10 @@ declare namespace LocalJSX {
85298537
* When `true`, the icon will be flipped when the element direction is right-to-left (`"rtl"`).
85308538
*/
85318539
"placeholderIconFlipRtl"?: boolean;
8540+
/**
8541+
* When `true`, the component's value can be read, but controls are not accessible and the value cannot be modified.
8542+
*/
8543+
"readOnly"?: boolean;
85328544
/**
85338545
* When `true`, the component must have a value in order for the form to submit.
85348546
*/
@@ -10123,6 +10135,10 @@ declare namespace LocalJSX {
1012310135
* Determines the type of positioning to use for the overlaid content. Using `"absolute"` will work for most cases. The component will be positioned inside of overflowing parent containers and will affect the container's layout. `"fixed"` should be used to escape an overflowing parent container, or when the reference element's `position` CSS property is `"fixed"`.
1012410136
*/
1012510137
"overlayPositioning"?: OverlayPositioning;
10138+
/**
10139+
* When `true`, the component's value can be read, but controls are not accessible and the value cannot be modified.
10140+
*/
10141+
"readOnly"?: boolean;
1012610142
/**
1012710143
* This `date` will be used as a reference to Daylight Savings Time when creating time zone item groups. It can be either a Date instance or a string in ISO format (`"YYYY-MM-DD"`, `"YYYY-MM-DDTHH:MM:SS.SSSZ"`).
1012810144
* @see [Date.prototype.toISOString](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toISOString)

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

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2002,4 +2002,23 @@ describe("calcite-combobox", () => {
20022002
await combobox.press("Enter");
20032003
expect(chips.length).toBe(2);
20042004
});
2005+
2006+
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+
});
2017+
2018+
const combobox = await page.find("calcite-combobox");
2019+
expect(await combobox.getProperty("open")).toBeFalsy();
2020+
await combobox.click();
2021+
await page.waitForChanges();
2022+
expect(await combobox.getProperty("open")).toBeFalsy();
2023+
});
20052024
});

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,11 @@ export class Combobox
309309
*/
310310
@Prop({ mutable: true }) filteredItems: HTMLCalciteComboboxItemElement[] = [];
311311

312+
/**
313+
* When `true`, the component's value can be read, but controls are not accessible and the value cannot be modified.
314+
*/
315+
@Prop({ reflect: true }) readOnly = false;
316+
312317
//--------------------------------------------------------------------------
313318
//
314319
// Event Listeners
@@ -807,6 +812,10 @@ export class Combobox
807812
};
808813

809814
clickHandler = (event: MouseEvent): void => {
815+
if (this.readOnly) {
816+
return;
817+
}
818+
810819
const composedPath = event.composedPath();
811820

812821
if (composedPath.some((node: HTMLElement) => node.tagName === "CALCITE-CHIP")) {

packages/calcite-components/src/components/input-time-zone/input-time-zone.tsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,11 @@ export class InputTimeZone
193193
this.selectedTimeZoneItem = timeZoneItem;
194194
}
195195

196+
/**
197+
* When `true`, the component's value can be read, but controls are not accessible and the value cannot be modified.
198+
*/
199+
@Prop({ reflect: true }) readOnly = false;
200+
196201
//--------------------------------------------------------------------------
197202
//
198203
// Public Methods
@@ -410,6 +415,7 @@ export class InputTimeZone
410415
onCalciteComboboxOpen={this.onComboboxOpen}
411416
open={this.open}
412417
overlayPositioning={this.overlayPositioning}
418+
readOnly={this.readOnly}
413419
scale={this.scale}
414420
selectionMode="single-persist"
415421
status={this.status}

packages/calcite-components/src/demos/input-time-zone.html

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,21 @@ <h1 style="margin: 0 auto; text-align: center">Select</h1>
6262
</div>
6363
</div>
6464

65+
<div class="parent">
66+
<div class="child right-aligned-text">Basic (offset mode) + readonly</div>
67+
<div class="child">
68+
<calcite-input-time-zone scale="s" read-only="true"></calcite-input-time-zone>
69+
</div>
70+
71+
<div class="child">
72+
<calcite-input-time-zone scale="m" read-only="true"></calcite-input-time-zone>
73+
</div>
74+
75+
<div class="child">
76+
<calcite-input-time-zone scale="l" read-only="true"></calcite-input-time-zone>
77+
</div>
78+
</div>
79+
6580
<div class="parent">
6681
<div class="child right-aligned-text">Basic (offset mode) + reference date</div>
6782
<div class="child">

0 commit comments

Comments
 (0)