Parcourir la source

fix hidden next/prev prevent navigation. fixes #3610

Adam Shaw il y a 9 ans
Parent
commit
7724d90836

+ 9 - 7
src/common/View.date-range.js

@@ -82,9 +82,8 @@ View.mixin({
 	// Builds a structure holding dates/ranges for rendering around the given date.
 	// Optional direction param indicates whether the date is being incremented/decremented
 	// from its previous value. decremented = -1, incremented = 1 (default).
-	buildDateProfile: function(givenDate, direction) {
+	buildDateProfile: function(date, direction, forceToValid) {
 		var validRange = this.buildValidRange();
-		var constrainedDate = constrainDate(givenDate, validRange);
 		var minTime = null;
 		var maxTime = null;
 		var currentInfo;
@@ -92,7 +91,11 @@ View.mixin({
 		var activeRange;
 		var isValid;
 
-		currentInfo = this.buildCurrentRangeInfo(constrainedDate, direction);
+		if (forceToValid) {
+			date = constrainDate(date, validRange);
+		}
+
+		currentInfo = this.buildCurrentRangeInfo(date, direction);
 		renderRange = this.buildRenderRange(currentInfo.range, currentInfo.unit);
 		activeRange = cloneRange(renderRange);
 
@@ -105,12 +108,11 @@ View.mixin({
 		this.adjustActiveRange(activeRange, minTime, maxTime);
 
 		activeRange = constrainRange(activeRange, validRange);
-		constrainedDate = constrainDate(constrainedDate, activeRange);
+		date = constrainDate(date, activeRange);
 
 		// it's invalid if the originally requested date is not contained,
 		// or if the range is completely outside of the valid range.
-		isValid = isDateWithinRange(givenDate, currentInfo.range) &&
-			doRangesIntersect(currentInfo.range, validRange);
+		isValid = doRangesIntersect(currentInfo.range, validRange);
 
 		return {
 			validRange: validRange,
@@ -121,7 +123,7 @@ View.mixin({
 			minTime: minTime,
 			maxTime: maxTime,
 			isValid: isValid,
-			date: constrainedDate,
+			date: date,
 			dateIncrement: this.buildDateIncrement(currentInfo.duration)
 				// pass a fallback (might be null) ^
 		};

+ 1 - 1
src/common/View.js

@@ -311,7 +311,7 @@ var View = FC.View = Class.extend(EmitterMixin, ListenerMixin, {
 
 	handleRawDate: function(date) {
 		var _this = this;
-		var dateProfile = this.buildDateProfile(date);
+		var dateProfile = this.buildDateProfile(date, null, true); // forceToValid=true
 
 		if (!this.isSameDateProfile(dateProfile)) { // real change
 			this.handleDate(dateProfile);

+ 12 - 0
tests/automated-better/toolbar/next-button.js

@@ -48,4 +48,16 @@ describe('next button', function() {
 			ToolbarUtils.expectButtonEnabled('next', false);
 		});
 	});
+
+	describe('when day after current day is a hidden day', function() {
+		pushOptions({
+			defaultDate: '2017-03-31',
+			defaultView: 'basicDay',
+			weekends: false
+		});
+		it('is enabled', function() {
+			initCalendar();
+			ToolbarUtils.expectButtonEnabled('next', true);
+		});
+	});
 });

+ 12 - 0
tests/automated-better/toolbar/prev-button.js

@@ -41,4 +41,16 @@ describe('prev button', function() {
 			ToolbarUtils.expectButtonEnabled('prev', false);
 		});
 	});
+
+	describe('when day before current day is a hidden day', function() {
+		pushOptions({
+			defaultDate: '2017-03-27',
+			defaultView: 'basicDay',
+			weekends: false
+		});
+		it('is enabled', function() {
+			initCalendar();
+			ToolbarUtils.expectButtonEnabled('prev', true);
+		});
+	});
 });