Skip to content

Commit c399f1f

Browse files
committed
Datepicker: Abstract mouseover logic to avoid explicit event trigger
The reliance on `.mouseover()` caused an issue in some circumstances (see #5816). The removal of `.mouseover()` broke keyboard navigation (see #10319). Fixes #10319 Closes gh-1290
1 parent 69f25db commit c399f1f

File tree

1 file changed

+20
-14
lines changed

1 file changed

+20
-14
lines changed

ui/datepicker.js

+20-14
Original file line numberDiff line numberDiff line change
@@ -799,12 +799,16 @@ $.extend(Datepicker.prototype, {
799799
datepicker_instActive = inst; // for delegate hover events
800800
inst.dpDiv.empty().append(this._generateHTML(inst));
801801
this._attachHandlers(inst);
802-
inst.dpDiv.find("." + this._dayOverClass + " a");
803802

804803
var origyearshtml,
805804
numMonths = this._getNumberOfMonths(inst),
806805
cols = numMonths[1],
807-
width = 17;
806+
width = 17,
807+
activeCell = inst.dpDiv.find( "." + this._dayOverClass + " a" );
808+
809+
if ( activeCell.length > 0 ) {
810+
datepicker_handleMouseover.apply( activeCell.get( 0 ) );
811+
}
808812

809813
inst.dpDiv.removeClass("ui-datepicker-multi-2 ui-datepicker-multi-3 ui-datepicker-multi-4").width("");
810814
if (cols > 1) {
@@ -2000,18 +2004,20 @@ function datepicker_bindHover(dpDiv) {
20002004
$(this).removeClass("ui-datepicker-next-hover");
20012005
}
20022006
})
2003-
.delegate(selector, "mouseover", function(){
2004-
if (!$.datepicker._isDisabledDatepicker( datepicker_instActive.inline ? dpDiv.parent()[0] : datepicker_instActive.input[0])) {
2005-
$(this).parents(".ui-datepicker-calendar").find("a").removeClass("ui-state-hover");
2006-
$(this).addClass("ui-state-hover");
2007-
if (this.className.indexOf("ui-datepicker-prev") !== -1) {
2008-
$(this).addClass("ui-datepicker-prev-hover");
2009-
}
2010-
if (this.className.indexOf("ui-datepicker-next") !== -1) {
2011-
$(this).addClass("ui-datepicker-next-hover");
2012-
}
2013-
}
2014-
});
2007+
.delegate( selector, "mouseover", datepicker_handleMouseover );
2008+
}
2009+
2010+
function datepicker_handleMouseover() {
2011+
if (!$.datepicker._isDisabledDatepicker( datepicker_instActive.inline? datepicker_instActive.dpDiv.parent()[0] : datepicker_instActive.input[0])) {
2012+
$(this).parents(".ui-datepicker-calendar").find("a").removeClass("ui-state-hover");
2013+
$(this).addClass("ui-state-hover");
2014+
if (this.className.indexOf("ui-datepicker-prev") !== -1) {
2015+
$(this).addClass("ui-datepicker-prev-hover");
2016+
}
2017+
if (this.className.indexOf("ui-datepicker-next") !== -1) {
2018+
$(this).addClass("ui-datepicker-next-hover");
2019+
}
2020+
}
20152021
}
20162022

20172023
/* jQuery extend now ignores nulls! */

0 commit comments

Comments
 (0)