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

DatePicker: disable input on mobile #4592

Open
wants to merge 4 commits into
base: rel-1.2
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@
<DocsAttributesItem Name="Inline" Type="bool" Default="false">
Display the calendar in an always-open state with the inline option.
</DocsAttributesItem>
<DocsAttributesItem Name="DisableMobile" Type="bool" Default="true">
<DocsAttributesItem Name="DisableMobile" Type="bool" Default="false">
If enabled, it disables the native input on mobile devices.
</DocsAttributesItem>
</DocsAttributes>
2 changes: 1 addition & 1 deletion Source/Blazorise/Components/DatePicker/DatePicker.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -533,7 +533,7 @@ protected override IReadOnlyList<TValue> InternalValue
/// <summary>
/// If enabled, it disables the native input on mobile devices.
/// </summary>
[Parameter] public bool DisableMobile { get; set; } = true;
[Parameter] public bool DisableMobile { get; set; }

#endregion
}
14 changes: 10 additions & 4 deletions Source/Blazorise/wwwroot/datePicker.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ export function initialize(element, elementId, options) {
const defaultOptions = {
enableTime: options.inputMode === 1,
dateFormat: options.inputMode === 1 ? 'Y-m-d H:i' : 'Y-m-d',
allowInput: true,
altInput: true,
allowInput: !(isMobile() && (options.disableMobile || false)),
altInput: !(isMobile() && (options.disableMobile || false)),
Comment on lines +42 to +43
Copy link
Contributor

Choose a reason for hiding this comment

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

My mind can't think today :D Is this right? Does it handle every case?
Might be a better read if you just bring the isMobile() out.
I.E
!IsMobile() || (isMobile() && !options.disableMobile)

But I think it's those pipes that are killing me, again is it a coalesce operation?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The logic is actually broken on flatpickr side. They don't detect the mobile device properly. So I was trying to come up with a workaround, even pushed a PR on their repo, but it still seems not to detect all of the mobile devices.

altFormat: options.displayFormat ? options.displayFormat : (options.inputMode === 1 ? 'Y-m-d H:i' : 'Y-m-d'),
defaultDate: options.defaultDate,
minDate: options.min,
Expand All @@ -52,7 +52,7 @@ export function initialize(element, elementId, options) {
clickOpens: !(options.readOnly || false),
disable: options.disabledDates || [],
inline: options.inline || false,
disableMobile: options.disableMobile || true,
disableMobile: options.disableMobile || false,
Copy link
Contributor

Choose a reason for hiding this comment

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

maybe I'm dumb, what is this? options.disableMobile || false? is this some kind of way to coalesce?

static: true
};

Expand All @@ -69,7 +69,7 @@ export function initialize(element, elementId, options) {

const picker = flatpickr(element, Object.assign({}, defaultOptions, pluginOptions));

if (options) {
if (options && picker.altInput) {
picker.altInput.disabled = options.disabled || false;
picker.altInput.readOnly = options.readOnly || false;
}
Expand Down Expand Up @@ -218,4 +218,10 @@ export function select(element, elementId, focus) {
if (picker && picker.altInput) {
utilities.select(picker.altInput, null, focus);
}
}

function isMobile() {
return /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(
navigator.userAgent
);
}