Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
E
Element
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
CI / CD Analytics
Repository Analytics
Value Stream Analytics
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
林焕东
Element
Commits
5b0b1e7e
Commit
5b0b1e7e
authored
Jan 31, 2018
by
Jiewei Qian
Committed by
杨奕
Jan 31, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
DatePicker: fix date clamping during navigation (#9577)
parent
ab2f3830
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
65 additions
and
48 deletions
+65
-48
packages/date-picker/src/panel/date-range.vue
packages/date-picker/src/panel/date-range.vue
+23
-19
packages/date-picker/src/panel/date.vue
packages/date-picker/src/panel/date.vue
+4
-3
packages/date-picker/src/util/index.js
packages/date-picker/src/util/index.js
+20
-26
test/unit/specs/date-picker.spec.js
test/unit/specs/date-picker.spec.js
+18
-0
No files found.
packages/date-picker/src/panel/date-range.vue
View file @
5b0b1e7e
...
@@ -190,6 +190,8 @@
...
@@ -190,6 +190,8 @@
isDate
,
isDate
,
modifyDate
,
modifyDate
,
modifyTime
,
modifyTime
,
prevYear
,
nextYear
,
prevMonth
,
prevMonth
,
nextMonth
nextMonth
}
from
'
../util
'
;
}
from
'
../util
'
;
...
@@ -557,17 +559,14 @@
...
@@ -557,17 +559,14 @@
}
}
},
},
// leftPrev*, rightNext* need to take care of `unlinkPanels`
leftPrevYear
()
{
leftPrevYear
()
{
this
.
leftDate
=
modifyDate
(
this
.
leftDate
,
this
.
leftYear
-
1
,
this
.
leftMonth
,
this
.
leftMonth
Date
);
this
.
leftDate
=
prevYear
(
this
.
left
Date
);
if
(
!
this
.
unlinkPanels
)
{
if
(
!
this
.
unlinkPanels
)
{
this
.
rightDate
=
nextMonth
(
this
.
leftDate
);
this
.
rightDate
=
nextMonth
(
this
.
leftDate
);
}
}
},
},
leftNextYear
()
{
this
.
leftDate
=
modifyDate
(
this
.
leftDate
,
this
.
leftYear
+
1
,
this
.
leftMonth
,
this
.
leftMonthDate
);
},
leftPrevMonth
()
{
leftPrevMonth
()
{
this
.
leftDate
=
prevMonth
(
this
.
leftDate
);
this
.
leftDate
=
prevMonth
(
this
.
leftDate
);
if
(
!
this
.
unlinkPanels
)
{
if
(
!
this
.
unlinkPanels
)
{
...
@@ -575,27 +574,15 @@
...
@@ -575,27 +574,15 @@
}
}
},
},
leftNextMonth
()
{
this
.
leftDate
=
nextMonth
(
this
.
leftDate
);
},
rightPrevYear
()
{
this
.
rightDate
=
modifyDate
(
this
.
rightDate
,
this
.
rightYear
-
1
,
this
.
rightMonth
,
this
.
rightMonthDate
);
},
rightNextYear
()
{
rightNextYear
()
{
if
(
!
this
.
unlinkPanels
)
{
if
(
!
this
.
unlinkPanels
)
{
this
.
leftDate
=
modifyDate
(
this
.
leftDate
,
this
.
leftYear
+
1
,
this
.
leftMonth
,
this
.
leftMonth
Date
);
this
.
leftDate
=
nextYear
(
this
.
left
Date
);
this
.
rightDate
=
nextMonth
(
this
.
leftDate
);
this
.
rightDate
=
nextMonth
(
this
.
leftDate
);
}
else
{
}
else
{
this
.
rightDate
=
modifyDate
(
this
.
rightDate
,
this
.
rightYear
+
1
,
this
.
rightMonth
,
this
.
rightMonth
Date
);
this
.
rightDate
=
nextYear
(
this
.
right
Date
);
}
}
},
},
rightPrevMonth
()
{
this
.
rightDate
=
prevMonth
(
this
.
rightDate
);
},
rightNextMonth
()
{
rightNextMonth
()
{
if
(
!
this
.
unlinkPanels
)
{
if
(
!
this
.
unlinkPanels
)
{
this
.
leftDate
=
nextMonth
(
this
.
leftDate
);
this
.
leftDate
=
nextMonth
(
this
.
leftDate
);
...
@@ -605,6 +592,23 @@
...
@@ -605,6 +592,23 @@
}
}
},
},
// leftNext*, rightPrev* are called when `unlinkPanels` is true
leftNextYear
()
{
this
.
leftDate
=
nextYear
(
this
.
leftDate
);
},
leftNextMonth
()
{
this
.
leftDate
=
nextMonth
(
this
.
leftDate
);
},
rightPrevYear
()
{
this
.
rightDate
=
prevYear
(
this
.
rightDate
);
},
rightPrevMonth
()
{
this
.
rightDate
=
prevMonth
(
this
.
rightDate
);
},
handleConfirm
(
visible
=
false
)
{
handleConfirm
(
visible
=
false
)
{
this
.
$emit
(
'
pick
'
,
[
this
.
minDate
,
this
.
maxDate
],
visible
);
this
.
$emit
(
'
pick
'
,
[
this
.
minDate
,
this
.
maxDate
],
visible
);
},
},
...
...
packages/date-picker/src/panel/date.vue
View file @
5b0b1e7e
...
@@ -150,7 +150,8 @@
...
@@ -150,7 +150,8 @@
prevYear
,
prevYear
,
nextYear
,
nextYear
,
prevMonth
,
prevMonth
,
nextMonth
nextMonth
,
changeYearMonthAndClampDate
}
from
'
../util
'
;
}
from
'
../util
'
;
import
Locale
from
'
element-ui/src/mixins/locale
'
;
import
Locale
from
'
element-ui/src/mixins/locale
'
;
import
ElInput
from
'
element-ui/packages/input
'
;
import
ElInput
from
'
element-ui/packages/input
'
;
...
@@ -304,7 +305,7 @@
...
@@ -304,7 +305,7 @@
this
.
date
=
modifyDate
(
this
.
date
,
this
.
year
,
month
,
1
);
this
.
date
=
modifyDate
(
this
.
date
,
this
.
year
,
month
,
1
);
this
.
emit
(
this
.
date
);
this
.
emit
(
this
.
date
);
}
else
{
}
else
{
this
.
date
=
modifyDate
(
this
.
date
,
this
.
year
,
month
,
this
.
monthDate
);
this
.
date
=
changeYearMonthAndClampDate
(
this
.
date
,
this
.
year
,
month
);
// TODO: should emit intermediate value ??
// TODO: should emit intermediate value ??
// this.emit(this.date);
// this.emit(this.date);
this
.
currentView
=
'
date
'
;
this
.
currentView
=
'
date
'
;
...
@@ -325,7 +326,7 @@
...
@@ -325,7 +326,7 @@
this
.
date
=
modifyDate
(
this
.
date
,
year
,
0
,
1
);
this
.
date
=
modifyDate
(
this
.
date
,
year
,
0
,
1
);
this
.
emit
(
this
.
date
);
this
.
emit
(
this
.
date
);
}
else
{
}
else
{
this
.
date
=
modifyDate
(
this
.
date
,
year
,
this
.
month
,
this
.
monthDate
);
this
.
date
=
changeYearMonthAndClampDate
(
this
.
date
,
year
,
this
.
month
);
// TODO: should emit intermediate value ??
// TODO: should emit intermediate value ??
// this.emit(this.date, true);
// this.emit(this.date, true);
this
.
currentView
=
'
month
'
;
this
.
currentView
=
'
month
'
;
...
...
packages/date-picker/src/util/index.js
View file @
5b0b1e7e
...
@@ -181,43 +181,37 @@ export const timeWithinRange = function(date, selectableRange, format) {
...
@@ -181,43 +181,37 @@ export const timeWithinRange = function(date, selectableRange, format) {
return
limitedDate
.
getTime
()
===
date
.
getTime
();
return
limitedDate
.
getTime
()
===
date
.
getTime
();
};
};
export
const
prevMonth
=
function
(
date
)
{
export
const
changeYearMonthAndClampDate
=
function
(
date
,
year
,
month
)
{
let
year
=
date
.
getFullYear
();
// clamp date to the number of days in `year`, `month`
let
month
=
date
.
getMonth
();
// eg: (2010-1-31, 2010, 2) => 2010-2-28
if
(
month
===
0
)
{
year
-=
1
;
month
=
11
;
}
else
{
month
-=
1
;
}
const
monthDate
=
Math
.
min
(
date
.
getDate
(),
getDayCountOfMonth
(
year
,
month
));
const
monthDate
=
Math
.
min
(
date
.
getDate
(),
getDayCountOfMonth
(
year
,
month
));
return
modifyDate
(
date
,
year
,
month
,
monthDate
);
return
modifyDate
(
date
,
year
,
month
,
monthDate
);
};
};
export
const
prevMonth
=
function
(
date
)
{
const
year
=
date
.
getFullYear
();
const
month
=
date
.
getMonth
();
return
month
===
0
?
changeYearMonthAndClampDate
(
date
,
year
-
1
,
11
)
:
changeYearMonthAndClampDate
(
date
,
year
,
month
-
1
);
};
export
const
nextMonth
=
function
(
date
)
{
export
const
nextMonth
=
function
(
date
)
{
let
year
=
date
.
getFullYear
();
const
year
=
date
.
getFullYear
();
let
month
=
date
.
getMonth
();
const
month
=
date
.
getMonth
();
if
(
month
===
11
)
{
return
month
===
11
year
+=
1
;
?
changeYearMonthAndClampDate
(
date
,
year
+
1
,
0
)
month
=
0
;
:
changeYearMonthAndClampDate
(
date
,
year
,
month
+
1
);
}
else
{
month
+=
1
;
}
const
monthDate
=
Math
.
min
(
date
.
getDate
(),
getDayCountOfMonth
(
year
,
month
));
return
modifyDate
(
date
,
year
,
month
,
monthDate
);
};
};
// check for leap year Feburary
export
const
prevYear
=
function
(
date
,
amount
=
1
)
{
export
const
prevYear
=
function
(
date
,
amount
=
1
)
{
const
year
=
date
.
getFullYear
()
-
amount
;
const
year
=
date
.
getFullYear
();
const
month
=
date
.
getMonth
();
const
month
=
date
.
getMonth
();
const
monthDate
=
Math
.
min
(
date
.
getDate
(),
getDayCountOfMonth
(
year
,
month
));
return
changeYearMonthAndClampDate
(
date
,
year
-
amount
,
month
);
return
modifyDate
(
date
,
year
,
month
,
monthDate
);
};
};
export
const
nextYear
=
function
(
date
,
amount
=
1
)
{
export
const
nextYear
=
function
(
date
,
amount
=
1
)
{
const
year
=
date
.
getFullYear
()
+
amount
;
const
year
=
date
.
getFullYear
();
const
month
=
date
.
getMonth
();
const
month
=
date
.
getMonth
();
const
monthDate
=
Math
.
min
(
date
.
getDate
(),
getDayCountOfMonth
(
year
,
month
));
return
changeYearMonthAndClampDate
(
date
,
year
+
amount
,
month
);
return
modifyDate
(
date
,
year
,
month
,
monthDate
);
};
};
test/unit/specs/date-picker.spec.js
View file @
5b0b1e7e
...
@@ -850,6 +850,24 @@ describe('DatePicker', () => {
...
@@ -850,6 +850,24 @@ describe('DatePicker', () => {
});
});
});
});
});
});
it
(
'
month label with fewer dates
'
,
done
=>
{
navigationTest
(
new
Date
(
2000
,
6
,
31
),
_
=>
{
const
$el
=
vm
.
$refs
.
compo
.
picker
.
$el
;
const
monthLabel
=
$el
.
querySelectorAll
(
'
.el-date-picker__header-label
'
)[
1
];
click
(
monthLabel
,
_
=>
{
setTimeout
(
_
=>
{
const
juneLabel
=
$el
.
querySelectorAll
(
'
.el-month-table td a
'
)[
5
];
juneLabel
.
click
();
setTimeout
(
_
=>
{
expect
(
getYearLabel
()).
to
.
include
(
'
2000
'
);
expect
(
getMonthLabel
()).
to
.
include
(
'
6
'
);
done
();
},
DELAY
);
},
DELAY
);
});
});
});
});
});
it
(
'
type:month
'
,
done
=>
{
it
(
'
type:month
'
,
done
=>
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment