@@ -10,7 +10,7 @@ import BaseComponent from './base-component.js'
10
10
import EventHandler from './dom/event-handler.js'
11
11
import Manipulator from './dom/manipulator.js'
12
12
import SelectorEngine from './dom/selector-engine.js'
13
- import { defineJQueryPlugin , isRTL } from './util/index.js'
13
+ import { defineJQueryPlugin , getElement , isRTL } from './util/index.js'
14
14
import {
15
15
convert12hTo24h ,
16
16
convert24hTo12h ,
@@ -76,10 +76,10 @@ const SELECTOR_WAS_VALIDATED = 'form.was-validated'
76
76
const Default = {
77
77
cancelButton : 'Cancel' ,
78
78
cancelButtonClasses : [ 'btn' , 'btn-sm' , 'btn-ghost-primary' ] ,
79
+ cleaner : true ,
79
80
confirmButton : 'OK' ,
80
81
confirmButtonClasses : [ 'btn' , 'btn-sm' , 'btn-primary' ] ,
81
- cleaner : true ,
82
- container : 'dropdown' ,
82
+ container : false ,
83
83
disabled : false ,
84
84
footer : true ,
85
85
hours : null ,
@@ -94,17 +94,18 @@ const Default = {
94
94
seconds : true ,
95
95
size : null ,
96
96
time : null ,
97
+ type : 'dropdown' ,
97
98
valid : false ,
98
99
variant : 'roll'
99
100
}
100
101
101
102
const DefaultType = {
102
103
cancelButton : '(boolean|string)' ,
103
104
cancelButtonClasses : '(array|string)' ,
105
+ cleaner : 'boolean' ,
104
106
confirmButton : '(boolean|string)' ,
105
107
confirmButtonClasses : '(array|string)' ,
106
- cleaner : 'boolean' ,
107
- container : 'string' ,
108
+ container : '(string|element|boolean)' ,
108
109
disabled : 'boolean' ,
109
110
footer : 'boolean' ,
110
111
hours : '(array|function|null)' ,
@@ -119,6 +120,7 @@ const DefaultType = {
119
120
seconds : '(array|boolean|function)' ,
120
121
size : '(string|null)' ,
121
122
time : '(date|string|null)' ,
123
+ type : 'string' ,
122
124
valid : 'boolean' ,
123
125
variant : 'string'
124
126
}
@@ -140,6 +142,7 @@ class TimePicker extends BaseComponent {
140
142
this . _popper = null
141
143
142
144
this . _input = null
145
+ this . _menu = null
143
146
this . _timePickerBody = null
144
147
145
148
this . _localizedTimePartials = getLocalizedTimePartials (
@@ -182,6 +185,11 @@ class TimePicker extends BaseComponent {
182
185
EventHandler . trigger ( this . _element , EVENT_SHOW )
183
186
this . _element . classList . add ( CLASS_NAME_SHOW )
184
187
this . _element . setAttribute ( 'aria-expanded' , true )
188
+
189
+ if ( this . _config . container ) {
190
+ this . _menu . classList . add ( CLASS_NAME_SHOW )
191
+ }
192
+
185
193
EventHandler . trigger ( this . _element , EVENT_SHOWN )
186
194
187
195
this . _createPopper ( )
@@ -196,6 +204,11 @@ class TimePicker extends BaseComponent {
196
204
197
205
this . _element . classList . remove ( CLASS_NAME_SHOW )
198
206
this . _element . setAttribute ( 'aria-expanded' , 'false' )
207
+
208
+ if ( this . _config . container ) {
209
+ this . _menu . classList . remove ( CLASS_NAME_SHOW )
210
+ }
211
+
199
212
EventHandler . trigger ( this . _element , EVENT_HIDDEN )
200
213
}
201
214
@@ -291,7 +304,7 @@ class TimePicker extends BaseComponent {
291
304
}
292
305
} )
293
306
294
- if ( this . _config . container === 'dropdown' ) {
307
+ if ( this . _config . type === 'dropdown' ) {
295
308
EventHandler . on ( this . _input . form , EVENT_SUBMIT , ( ) => {
296
309
if ( this . _input . form . classList . contains ( CLASS_NAME_WAS_VALIDATED ) ) {
297
310
if ( Number . isNaN ( Date . parse ( `1970-01-01 ${ this . _input . value } ` ) ) ) {
@@ -328,7 +341,7 @@ class TimePicker extends BaseComponent {
328
341
329
342
this . _element . classList . toggle ( CLASS_NAME_IS_INVALID , this . _config . invalid )
330
343
331
- if ( this . _config . container === 'dropdown' ) {
344
+ if ( this . _config . type === 'dropdown' ) {
332
345
this . _element . append ( this . _createTimePickerInputGroup ( ) )
333
346
334
347
const dropdownEl = document . createElement ( 'div' )
@@ -339,11 +352,17 @@ class TimePicker extends BaseComponent {
339
352
dropdownEl . append ( this . _createTimePickerFooter ( ) )
340
353
}
341
354
342
- this . _element . append ( dropdownEl )
355
+ const { container } = this . _config
356
+ if ( container ) {
357
+ container . append ( dropdownEl )
358
+ } else {
359
+ this . _element . append ( dropdownEl )
360
+ }
361
+
343
362
this . _menu = dropdownEl
344
363
}
345
364
346
- if ( this . _config . container === 'inline' ) {
365
+ if ( this . _config . type === 'inline' ) {
347
366
this . _element . append ( this . _createTimePickerBody ( ) )
348
367
}
349
368
}
@@ -797,8 +816,28 @@ class TimePicker extends BaseComponent {
797
816
} )
798
817
}
799
818
800
- // Static
819
+ _configAfterMerge ( config ) {
820
+ if ( config . container === 'dropdown' || config . container === 'inline' ) {
821
+ config . type = config . container
822
+ }
823
+
824
+ if ( config . container === true ) {
825
+ config . container = document . body
826
+ }
827
+
828
+ if (
829
+ typeof config . container === 'object' ||
830
+ ( typeof config . container === 'string' &&
831
+ config . container === 'dropdown' &&
832
+ config . container === 'inline' )
833
+ ) {
834
+ config . container = getElement ( config . container )
835
+ }
801
836
837
+ return config
838
+ }
839
+
840
+ // Static
802
841
static timePickerInterface ( element , config ) {
803
842
const data = TimePicker . getOrCreateInstance ( element , config )
804
843
0 commit comments