@@ -10,7 +10,7 @@ import BaseComponent from './base-component.js'
1010import EventHandler from './dom/event-handler.js'
1111import Manipulator from './dom/manipulator.js'
1212import SelectorEngine from './dom/selector-engine.js'
13- import { defineJQueryPlugin , isRTL } from './util/index.js'
13+ import { defineJQueryPlugin , getElement , isRTL } from './util/index.js'
1414import {
1515 convert12hTo24h ,
1616 convert24hTo12h ,
@@ -76,10 +76,10 @@ const SELECTOR_WAS_VALIDATED = 'form.was-validated'
7676const Default = {
7777 cancelButton : 'Cancel' ,
7878 cancelButtonClasses : [ 'btn' , 'btn-sm' , 'btn-ghost-primary' ] ,
79+ cleaner : true ,
7980 confirmButton : 'OK' ,
8081 confirmButtonClasses : [ 'btn' , 'btn-sm' , 'btn-primary' ] ,
81- cleaner : true ,
82- container : 'dropdown' ,
82+ container : false ,
8383 disabled : false ,
8484 footer : true ,
8585 hours : null ,
@@ -94,17 +94,18 @@ const Default = {
9494 seconds : true ,
9595 size : null ,
9696 time : null ,
97+ type : 'dropdown' ,
9798 valid : false ,
9899 variant : 'roll'
99100}
100101
101102const DefaultType = {
102103 cancelButton : '(boolean|string)' ,
103104 cancelButtonClasses : '(array|string)' ,
105+ cleaner : 'boolean' ,
104106 confirmButton : '(boolean|string)' ,
105107 confirmButtonClasses : '(array|string)' ,
106- cleaner : 'boolean' ,
107- container : 'string' ,
108+ container : '(string|element|boolean)' ,
108109 disabled : 'boolean' ,
109110 footer : 'boolean' ,
110111 hours : '(array|function|null)' ,
@@ -119,6 +120,7 @@ const DefaultType = {
119120 seconds : '(array|boolean|function)' ,
120121 size : '(string|null)' ,
121122 time : '(date|string|null)' ,
123+ type : 'string' ,
122124 valid : 'boolean' ,
123125 variant : 'string'
124126}
@@ -140,6 +142,7 @@ class TimePicker extends BaseComponent {
140142 this . _popper = null
141143
142144 this . _input = null
145+ this . _menu = null
143146 this . _timePickerBody = null
144147
145148 this . _localizedTimePartials = getLocalizedTimePartials (
@@ -182,6 +185,11 @@ class TimePicker extends BaseComponent {
182185 EventHandler . trigger ( this . _element , EVENT_SHOW )
183186 this . _element . classList . add ( CLASS_NAME_SHOW )
184187 this . _element . setAttribute ( 'aria-expanded' , true )
188+
189+ if ( this . _config . container ) {
190+ this . _menu . classList . add ( CLASS_NAME_SHOW )
191+ }
192+
185193 EventHandler . trigger ( this . _element , EVENT_SHOWN )
186194
187195 this . _createPopper ( )
@@ -196,6 +204,11 @@ class TimePicker extends BaseComponent {
196204
197205 this . _element . classList . remove ( CLASS_NAME_SHOW )
198206 this . _element . setAttribute ( 'aria-expanded' , 'false' )
207+
208+ if ( this . _config . container ) {
209+ this . _menu . classList . remove ( CLASS_NAME_SHOW )
210+ }
211+
199212 EventHandler . trigger ( this . _element , EVENT_HIDDEN )
200213 }
201214
@@ -291,7 +304,7 @@ class TimePicker extends BaseComponent {
291304 }
292305 } )
293306
294- if ( this . _config . container === 'dropdown' ) {
307+ if ( this . _config . type === 'dropdown' ) {
295308 EventHandler . on ( this . _input . form , EVENT_SUBMIT , ( ) => {
296309 if ( this . _input . form . classList . contains ( CLASS_NAME_WAS_VALIDATED ) ) {
297310 if ( Number . isNaN ( Date . parse ( `1970-01-01 ${ this . _input . value } ` ) ) ) {
@@ -328,7 +341,7 @@ class TimePicker extends BaseComponent {
328341
329342 this . _element . classList . toggle ( CLASS_NAME_IS_INVALID , this . _config . invalid )
330343
331- if ( this . _config . container === 'dropdown' ) {
344+ if ( this . _config . type === 'dropdown' ) {
332345 this . _element . append ( this . _createTimePickerInputGroup ( ) )
333346
334347 const dropdownEl = document . createElement ( 'div' )
@@ -339,11 +352,17 @@ class TimePicker extends BaseComponent {
339352 dropdownEl . append ( this . _createTimePickerFooter ( ) )
340353 }
341354
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+
343362 this . _menu = dropdownEl
344363 }
345364
346- if ( this . _config . container === 'inline' ) {
365+ if ( this . _config . type === 'inline' ) {
347366 this . _element . append ( this . _createTimePickerBody ( ) )
348367 }
349368 }
@@ -797,8 +816,28 @@ class TimePicker extends BaseComponent {
797816 } )
798817 }
799818
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+ }
801836
837+ return config
838+ }
839+
840+ // Static
802841 static timePickerInterface ( element , config ) {
803842 const data = TimePicker . getOrCreateInstance ( element , config )
804843
0 commit comments