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(ui5-time-picker): display value state message in popover's header correctly on mobile #10795

Merged
merged 2 commits into from
Feb 12, 2025
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
7 changes: 6 additions & 1 deletion packages/main/src/DateTimeInput.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import customElement from "@ui5/webcomponents-base/dist/decorators/customElement
// Styles
import Input from "./Input.js";
import { property } from "@ui5/webcomponents-base/dist/decorators.js";
import { isDesktop, isPhone, isTablet } from "@ui5/webcomponents-base/dist/Device.js";

/**
* Extention of the UI5 Input, so we do not modify Input's private properties within the datetime components.
Expand All @@ -27,7 +28,11 @@ class DateTimeInput extends Input {
* @override
*/
get hasValueStateMessage() {
return this._shouldOpenValueStatePopover && super.hasValueStateMessage;
return this._shouldOpenValueStatePopover && super.hasValueStateMessage && !this._isMobileDevice;
}

get _isMobileDevice() {
return !isDesktop() && (isPhone() || isTablet());
}
}

Expand Down
50 changes: 24 additions & 26 deletions packages/main/src/TimePicker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ import {
} from "@ui5/webcomponents-base/dist/Keys.js";
import UI5Date from "@ui5/webcomponents-localization/dist/dates/UI5Date.js";
import type Popover from "./Popover.js";
import type ResponsivePopover from "./ResponsivePopover.js";
import TimePickerTemplate from "./TimePickerTemplate.js";
import type DateTimeInput from "./DateTimeInput.js";
import type { InputAccInfo } from "./Input.js";
Expand Down Expand Up @@ -314,6 +313,12 @@ class TimePicker extends UI5Element implements IFormInputElement {
@query("[ui5-time-selection-clocks]")
_timeSelectionClocks?: TimeSelectionClocks;

@query("[ui5-popover]")
_inputsPopover?: Popover;
hinzzx marked this conversation as resolved.
Show resolved Hide resolved

@query("[ui5-datetime-input]")
_dateTimeInput?: DateTimeInput;
hinzzx marked this conversation as resolved.
Show resolved Hide resolved

tempValue?: string;

@i18n("@ui5/webcomponents")
Expand Down Expand Up @@ -408,12 +413,17 @@ class TimePicker extends UI5Element implements IFormInputElement {
return !isDesktop() && (isPhone() || isTablet());
}

get shouldDisplayValueStateMessageInResponsivePopover() {
return this.hasValueStateText && !this._inputsPopover?.open;
}

onTimeSelectionChange(e: CustomEvent<TimeSelectionChangeEventDetail>) {
this.tempValue = e.detail.value; // every time the user changes the time selection -> update tempValue
}

_togglePicker() {
this.open = !this.open;
this._isMobileDevice && (this._inputsPopover!.open = false);
hinzzx marked this conversation as resolved.
Show resolved Hide resolved
}

submitPickers() {
Expand Down Expand Up @@ -445,9 +455,9 @@ class TimePicker extends UI5Element implements IFormInputElement {
*/
openInputsPopover() {
this.tempValue = this.value && this.isValid(this.value) ? this.value : this.getFormat().format(UI5Date.getInstance());
const popover = this._getInputsPopover();
popover.opener = this;
popover.open = true;
const popover = this._inputsPopover;
popover!.opener = this;
popover!.open = true;
this._isInputsPopoverOpen = true;
}

Expand All @@ -457,8 +467,8 @@ class TimePicker extends UI5Element implements IFormInputElement {
* @returns Resolves when the Inputs popover is closed
*/
closeInputsPopover() {
const popover = this._getInputsPopover();
popover.open = false;
const popover = this._inputsPopover;
hinzzx marked this conversation as resolved.
Show resolved Hide resolved
popover!.open = false;
}

toggleInputsPopover() {
Expand All @@ -483,8 +493,8 @@ class TimePicker extends UI5Element implements IFormInputElement {
}

onInputsPopoverAfterOpen() {
const popover = this._getInputsPopover();
popover.querySelector<TimeSelectionInputs>("[ui5-time-selection-inputs]")!._addNumericAttributes();
const popover = this._inputsPopover;
popover!.querySelector<TimeSelectionInputs>("[ui5-time-selection-inputs]")!._addNumericAttributes();
}

onInputsPopoverAfterClose() {
Expand Down Expand Up @@ -560,20 +570,8 @@ class TimePicker extends UI5Element implements IFormInputElement {
return !this.disabled && this._isMobileDevice;
}

_getPopover() {
return this.shadowRoot!.querySelector<ResponsivePopover>("[ui5-responsive-popover]")!;
}

_getInputsPopover() {
return this.shadowRoot!.querySelector<Popover>("[ui5-popover]")!;
}

_getDateTimeInput(): DateTimeInput {
return this.shadowRoot!.querySelector<DateTimeInput>("[ui5-datetime-input]")!;
}

_getInputField() {
const input = this._getDateTimeInput();
const input = this._dateTimeInput;
return input && input.getInputDOMRef();
}

Expand All @@ -588,7 +586,7 @@ class TimePicker extends UI5Element implements IFormInputElement {

const target = e.target as HTMLElement;

if (target && this.open && this._getDateTimeInput().id === target.id && (isTabNext(e) || isTabPrevious(e) || isF6Next(e) || isF6Previous(e))) {
if (target && this.open && this._dateTimeInput!.id === target.id && (isTabNext(e) || isTabPrevious(e) || isF6Next(e) || isF6Previous(e))) {
this._togglePicker();
}
if (this.open) {
Expand Down Expand Up @@ -703,16 +701,16 @@ class TimePicker extends UI5Element implements IFormInputElement {
* Hides mobile device keyboard by temporary setting the input to readonly state.
*/
_hideMobileKeyboard() {
this._getDateTimeInput().readonly = true;
setTimeout(() => { this._getDateTimeInput().readonly = false; }, 0);
this._dateTimeInput!.readonly = true;
setTimeout(() => { this._dateTimeInput!.readonly = false; }, 0);
}

_onfocusin(e: FocusEvent) {
if (this._isMobileDevice) {
this._hideMobileKeyboard();
if (this._isInputsPopoverOpen) {
const popover = this._getInputsPopover();
popover.applyFocus();
const popover = this._inputsPopover;
popover!.applyFocus();
}
e.preventDefault();
}
Expand Down
2 changes: 1 addition & 1 deletion packages/main/src/TimePickerPopoverTemplate.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export default function TimePickerPopoverTemplate(this: TimePicker) {
onWheel={this._handleWheel}
onKeyDown={this._onkeydown}
>
{this.hasValueStateText && valueStateTextHeader.call(this)}
{this.shouldDisplayValueStateMessageInResponsivePopover && valueStateTextHeader.call(this)}

<TimeSelectionClocks
id={`${this._id}-time-sel`}
Expand Down
2 changes: 1 addition & 1 deletion packages/main/src/TimePickerTemplate.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export default function TimePickerTemplate(this: TimePicker) {
onFocusIn={this._onfocusin}
onKeyDown={this._onkeydown}
>
{this.valueStateMessage.length > 0 && !this.open &&
{this.valueStateMessage.length > 0 && !this.open && !this._isMobileDevice &&
hinzzx marked this conversation as resolved.
Show resolved Hide resolved
<slot
name="valueStateMessage"
slot="valueStateMessage"
Expand Down