)}
{this.range && this.layout === "vertical" && this.scale !== "s" && (
-
+
)}
{this.range && (
@@ -626,15 +630,14 @@ export class InputDatePicker
aria-expanded={toAriaBoolean(this.open)}
aria-haspopup="dialog"
class={{
- input: true,
- "border-top-color-one": this.layout === "vertical" && this.range,
+ [CSS.input]: true,
+ [CSS.inputBorderTopColorOne]: this.layout === "vertical" && this.range,
}}
disabled={disabled}
icon="calendar"
onCalciteInputTextInput={this.calciteInternalInputInputHandler}
onCalciteInternalInputTextBlur={this.calciteInternalInputBlurHandler}
onCalciteInternalInputTextFocus={this.endInputFocus}
- onFocus={this.startEndInputFocus}
placeholder={this.localeData?.placeholder}
readOnly={readOnly}
role="combobox"
@@ -672,6 +675,8 @@ export class InputDatePicker
@Element() el: HTMLCalciteInputDatePickerElement;
+ private currentOpenInput: "start" | "end";
+
private datePickerEl: HTMLCalciteDatePickerElement;
private dialogId = `date-picker-dialog--${guid()}`;
@@ -696,8 +701,6 @@ export class InputDatePicker
@State() focusedInput: "start" | "end" = "start";
- private lastBlurredInput: "start" | "end" | "none" = "none";
-
@State() private localeData: DateLocaleData;
private startInput: HTMLCalciteInputElement;
@@ -741,14 +744,32 @@ export class InputDatePicker
//
//--------------------------------------------------------------------------
- private onInputWrapperClick = () => {
- if (this.range && this.lastBlurredInput !== "none" && this.open) {
- // we keep the date-picker open when moving between inputs
- } else {
+ private onInputWrapperPointerDown = (): void => {
+ this.currentOpenInput = this.focusedInput;
+ };
+
+ private onInputWrapperClick = (event: MouseEvent) => {
+ const { range, endInput, startInput, currentOpenInput } = this;
+ if (!range || !this.open) {
this.open = !this.open;
+ return;
}
- this.lastBlurredInput = "none";
+ const currentTarget = event.currentTarget as HTMLDivElement;
+ const position = currentTarget.getAttribute("data-position") as "start" | "end";
+ const path = event.composedPath();
+ const wasToggleClicked = path.find((el: HTMLElement) => {
+ return el.classList?.contains(CSS.toggleIcon);
+ });
+
+ if (wasToggleClicked) {
+ const targetInput = position === "start" ? startInput : endInput;
+ targetInput.setFocus();
+ }
+
+ if (currentOpenInput === position) {
+ this.open = !this.open;
+ }
};
setFilteredPlacements = (): void => {
@@ -803,9 +824,8 @@ export class InputDatePicker
this.endInput = el;
};
- deactivate = (): void => {
+ private blurHandler = (): void => {
this.open = false;
- this.lastBlurredInput = "none";
};
private commitValue(): void {
@@ -886,12 +906,6 @@ export class InputDatePicker
this.focusedInput = "start";
};
- startEndInputFocus = (event: FocusEvent): void => {
- const blurredEl = event.relatedTarget as HTMLElement;
- this.lastBlurredInput =
- blurredEl === this.startInput ? "start" : blurredEl === this.endInput ? "end" : "none";
- };
-
endInputFocus = (): void => {
this.focusedInput = "end";
};
diff --git a/packages/calcite-components/src/components/input-date-picker/resources.ts b/packages/calcite-components/src/components/input-date-picker/resources.ts
index e79b51c7e74..5c3a881fab2 100644
--- a/packages/calcite-components/src/components/input-date-picker/resources.ts
+++ b/packages/calcite-components/src/components/input-date-picker/resources.ts
@@ -1,6 +1,15 @@
export const CSS = {
assistiveText: "assistive-text",
+ calendarWrapper: "calendar-wrapper",
+ calendarWrapperEnd: "calendar-wrapper--end",
+ horizontalArrowContainer: "horizontal-arrow-container",
+ inputBorderTopColorOne: "border-top-color-one",
+ inputContainer: "input-container",
+ inputNoBottomBorder: "no-bottom-border",
+ inputWrapper: "input-wrapper",
+ input: "input",
menu: "menu-container",
menuActive: "menu-container--active",
toggleIcon: "toggle-icon",
+ verticalArrowContainer: "vertical-arrow-container",
};