@@ -19,12 +19,12 @@ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
19
19
return to . concat ( ar || Array . prototype . slice . call ( from ) ) ;
20
20
} ;
21
21
import dayjs from 'dayjs' ;
22
- import { useComponent , useEvent , useReady , useState , } from 'functional-mini/component' ;
22
+ import { useComponent , useEvent , useReady , useState , useEffect , } from 'functional-mini/component' ;
23
23
import { mountComponent } from '../_util/component' ;
24
24
import { useComponentEvent } from '../_util/hooks/useComponentEvent' ;
25
25
import { hasValue , useMergedState } from '../_util/hooks/useMergedState' ;
26
26
import { defaultLocaleText , } from './props' ;
27
- import { defaultMonthRange , getMonthListFromRange , getSelectionModeFromValue , renderCells , } from './utils' ;
27
+ import { defaultMonthRange , getMonthListFromRange , getSelectionModeFromValue , renderCells , getScrollIntoViewId , } from './utils' ;
28
28
function getBoundingClientRect ( instance , selector ) {
29
29
return new Promise ( function ( resolve , reject ) {
30
30
instance
@@ -54,6 +54,7 @@ var Calendar = function (props) {
54
54
var _c = useMergedState ( props . defaultValue , {
55
55
value : props . value ,
56
56
} ) , value = _c [ 0 ] , setValue = _c [ 1 ] ;
57
+ var _d = useState ( '' ) , scrollIntoViewId = _d [ 0 ] , setScrollIntoViewId = _d [ 1 ] ;
57
58
var selectionModeFromValue = getSelectionModeFromValue ( value ) ;
58
59
var selectionMode = ( _b = ( _a = props . selectionMode ) !== null && _a !== void 0 ? _a : selectionModeFromValue ) !== null && _b !== void 0 ? _b : 'range' ;
59
60
var triggerEvent = useComponentEvent ( props ) . triggerEvent ;
@@ -125,11 +126,11 @@ var Calendar = function (props) {
125
126
cells : cells ,
126
127
} ;
127
128
} ) ;
128
- var _d = useState ( 0 ) , headerState = _d [ 0 ] , setHeaderState = _d [ 1 ] ;
129
+ var _e = useState ( 0 ) , headerState = _e [ 0 ] , setHeaderState = _e [ 1 ] ;
129
130
useEvent ( 'setCurrentMonth' , function ( e ) {
130
131
setHeaderState ( e . month ) ;
131
132
} ) ;
132
- var _e = useState ( null ) , elementSize = _e [ 0 ] , setElementSize = _e [ 1 ] ;
133
+ var _f = useState ( null ) , elementSize = _f [ 0 ] , setElementSize = _f [ 1 ] ;
133
134
var componentInstance = useComponent ( ) ;
134
135
function measurement ( ) {
135
136
Promise . all ( [
@@ -154,8 +155,22 @@ var Calendar = function (props) {
154
155
setElementSize ( null ) ;
155
156
} ) ;
156
157
}
158
+ useEffect ( function ( ) {
159
+ // 滚动到已选的位置
160
+ props . changedScrollIntoView &&
161
+ setScrollIntoViewId ( getScrollIntoViewId ( value ) ) ;
162
+ } , [ value ] ) ;
157
163
useReady ( function ( ) {
158
164
measurement ( ) ;
165
+ // 初始化默认值时,滚动到选中位置
166
+ var isControl = hasValue ( props . value ) ;
167
+ if ( isControl ) {
168
+ setScrollIntoViewId ( getScrollIntoViewId ( props . value ) ) ;
169
+ }
170
+ else {
171
+ props . defaultValue &&
172
+ setScrollIntoViewId ( getScrollIntoViewId ( props . defaultValue ) ) ;
173
+ }
159
174
} , [ ] ) ;
160
175
useEvent ( 'measurement' , function ( ) {
161
176
// 组件如果内嵌在 slot 里, 一定会被渲染出来, 但是此时 cellHight 为 0
@@ -169,6 +184,7 @@ var Calendar = function (props) {
169
184
markItems : markItems ,
170
185
monthList : monthList ,
171
186
headerState : headerState ,
187
+ scrollIntoViewId : scrollIntoViewId ,
172
188
} ;
173
189
} ;
174
190
mountComponent ( Calendar , {
0 commit comments