-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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(datepicker): double tap required to select a date with the datepicker on ios #2810
Comments
Thanks for an issue, it's interesting. |
Issue reported by Frank84 is happening to me as well. |
First touch on iOS treated as hover, second as a click. So I have not much options: remove hover effect and replace with mouse enter/leave and manipulate selection class from js. Which, of course, will affect performance |
Will there be an update with the mentioned change or ignore the issue to not affect performance? |
A dirty hack is to "remove" the hover event listener when the device is "recognized" to be an iPhone/iPad etc (FYI i did this for the RatingModule but it should work for datepicker also):
Where ngxRating is a template reference to the rating component : |
if it helps anyone, you can also capture and extend the hover listener, to manually update the value or close the picker - hacky but works until a formalised solution is implemented // component.html
<input type="text"
class="form-control"
#datePicker="bsDatepicker"
(onShown)="onShowPicker($event)"
bsDatepicker>
// component.ts
...
onShowPicker(container) {
const dayHoverHandler = container.dayHoverHandler;
const hoverWrapper = function($event) {
const { cell, isHovered } = $event;
// do whatever with hovered cell/event
return dayHoverHandler($event);
};
container.dayHoverHandler = hoverWrapper;
} |
Thanks to the suggestions from @danitt and @ktsangop I managed to solve that issue on iOS devices. Here is the solution. It works for BsDatePicker and BsDateRangePicker: // component.html
<input
bsDatepicker
#datepicker="bsDatepicker"
type="text"
class="form-control"
(onShown)="onShowPicker($event)"
>
// component.ts
@ViewChild('datepicker')
private _picker: BsDatepickerDirective;
onShowPicker(event) {
const dayHoverHandler = event.dayHoverHandler;
const hoverWrapper = (hoverEvent) => {
const { cell, isHovered } = hoverEvent;
if ((isHovered &&
!!navigator.platform &&
/iPad|iPhone|iPod/.test(navigator.platform)) &&
'ontouchstart' in window
) {
(this._picker as any)._datepickerRef.instance.daySelectHandler(cell);
}
return dayHoverHandler(hoverEvent);
};
event.dayHoverHandler = hoverWrapper;
} |
i'm having the same issue. The first click shows the form input error (required), and the second click on the datepicker fills the input correctly. I tried the suggestions above, but none of them worked. I'm using angular 7. component.html
component.ts
|
I have a same issue here, Angular 7 with Reactive Form input which is bsDatePicker 2nd click => Everything is going well, get the value, no required field waring. |
I'm also facing this with Angular 7.2.6. Strangely it was enough for me to just add the hover handler. Then the double-click issue on day selection disappeared in Safari 12 / iOS 12.1.
|
Hi @iaguilarmartin , I tried your code which is working properly but in console i am getting below error. |
Due to iOS 13, the navigator.platform for iPad has changed, and also, they're firing two events, so the code above has to be: if ((isHovered && cell.isHovered &&
Modernizr.touchEvents && vendor == 'Apple'
) { |
But Modernizr and vendor are displaying as an error. how to import these two in a component? |
@pavantripsolver I've downloaded Modernizer to the same folder as the .ts file (with only the touchevents feature). I also use Bowser to detect if it is an iOS device(just install it with npm). import * as Bowser from 'bowser';
import './modernizr.js';
...
export class XXXX {
bw = null;
constructor() {
this.bw = Bowser.getParser(window.navigator.userAgent);
}
public iosLessThan13() {
if (this.bw.parsedResult.os.name == 'iOS' && parseFloat(this.bw.parsedResult.os.version) < 13) {
return true;
} else {
return false;
}
}
public iosMoreThan12() {
if (this.bw.parsedResult.os.name == 'macOS' || // iPad OS ¬¬
(this.bw.parsedResult.os.name == 'iOS' && parseFloat(this.bw.parsedResult.os.version) >= 13)) {
return true;
} else {
return false;
}
}
public isSafariTouch() {
if (window['Modernizr']['touchevents'] && this.bw.parsedResult.platform.vendor == 'Apple') {
return true;
} else {
return false;
}
}
onShowPicker(event: any) {
const dayHoverHandler = event.dayHoverHandler;
const hoverWrapper = (hoverEvent: any) => {
const { cell, isHovered } = hoverEvent;
if (isHovered && this.isSafariTouch() &&
((this.iosMoreThan12() && cell.isHovered) || this.iosLessThan13())
) {
try {
(this._picker as any)._datepickerRef.instance.daySelectHandler(cell);
} catch (e) {}
}
return dayHoverHandler(hoverEvent);
};
event.dayHoverHandler = hoverWrapper;
} |
I'm getting same issue in angular 6, but not all the time. I am able reproduce it very few time. but I want to resolve it. Any solutions will be appreciated. |
I'm having the same issue in angular 8. Will also try a workaround, though it would be great if this were fixed! |
Issue was due to .touched which I was using in HTML for validation. This worked for me :) I added validateDate() which will dynamically add .touched validation which we are using for required field. date.component.html <input type="text" formControlName="" (focusout)="validateDate()" <ng-container *ngFor="let error of config.validations"> date.component.ts validateDate(): void { |
I had the same issue but in web application. Device: Laptop. OS - Windows 10. Browser - Firefox, chrome |
For those who cannot wait for the fix in 5.7.0 please find this reusable directive:
|
this is not working for me for angular 8 and ngx-bootstrap "ngx-bootstrap": "5.1.2", |
Try latest v5, or v6 |
Yeah, in latest 6.1.0 it should work correctly cc @Amolip |
Hi team,
Thanks for the response.
I am using this at entire project and other things I am using from ngx
bootstrap,not possible to update.
Please provide solution.
Regards,
Amol
…On Thu, 3 Sep, 2020, 12:27 am Dmitriy Danilov, ***@***.***> wrote:
Yeah, in latest 6.1.0 it should work correctly
This fix was released in 6.0.0, but, had some other issues with hovering
on macOS, and in 6.1.0 it was also fixed
cc @Amolip <https://github.com/Amolip>
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#2810 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AQLUCQLEABFXJH5XMC3QGJTSD2ITPANCNFSM4D6DEJGA>
.
|
Looks like this was fixed in version 5.7.0 but that version was never published to npm. |
Is there a config option we can pass with the datepicker so it automatically closes the popup when the user touch a date on ios? At the moment it triggers the isHover state, adding the hover css on the date. An additional touch is then require to select the date and close the modal.
Versions:
ngx-bootstrap: 1.9.3
Angular: 4.3.3
Bootstrap: 3.3.7
The text was updated successfully, but these errors were encountered: