44 * This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
55 */
66import { Overlay } from '@vaadin/overlay/src/vaadin-overlay.js' ;
7- import { PositionMixin } from '@vaadin/overlay/src/vaadin-overlay-position-mixin.js' ;
87import { css , registerStyles } from '@vaadin/vaadin-themable-mixin/vaadin-themable-mixin.js' ;
8+ import { ComboBoxOverlayMixin } from './vaadin-combo-box-overlay-mixin.js' ;
99
1010registerStyles (
1111 'vaadin-combo-box-overlay' ,
@@ -29,73 +29,28 @@ let memoizedTemplate;
2929 * An element used internally by `<vaadin-combo-box>`. Not intended to be used separately.
3030 *
3131 * @extends Overlay
32+ * @mixes ComboBoxOverlayMixin
3233 * @private
3334 */
34- export class ComboBoxOverlay extends PositionMixin ( Overlay ) {
35+ export class ComboBoxOverlay extends ComboBoxOverlayMixin ( Overlay ) {
3536 static get is ( ) {
3637 return 'vaadin-combo-box-overlay' ;
3738 }
3839
3940 static get template ( ) {
4041 if ( ! memoizedTemplate ) {
4142 memoizedTemplate = super . template . cloneNode ( true ) ;
42- memoizedTemplate . content . querySelector ( '[part~="overlay"]' ) . removeAttribute ( 'tabindex' ) ;
43- }
44-
45- return memoizedTemplate ;
46- }
4743
48- static get observers ( ) {
49- return [ '_setOverlayWidth(positionTarget, opened)' ] ;
50- }
51-
52- connectedCallback ( ) {
53- super . connectedCallback ( ) ;
44+ const overlay = memoizedTemplate . content . querySelector ( '[part~="overlay"]' ) ;
45+ overlay . removeAttribute ( 'tabindex' ) ;
5446
55- const comboBox = this . _comboBox ;
47+ const loader = document . createElement ( 'div' ) ;
48+ loader . setAttribute ( 'part' , 'loader' ) ;
5649
57- const hostDir = comboBox && comboBox . getAttribute ( 'dir' ) ;
58- if ( hostDir ) {
59- this . setAttribute ( 'dir' , hostDir ) ;
50+ overlay . insertBefore ( loader , overlay . firstElementChild ) ;
6051 }
61- }
62-
63- ready ( ) {
64- super . ready ( ) ;
65- const loader = document . createElement ( 'div' ) ;
66- loader . setAttribute ( 'part' , 'loader' ) ;
67- const content = this . shadowRoot . querySelector ( '[part~="content"]' ) ;
68- content . parentNode . insertBefore ( loader , content ) ;
69- }
70-
71- /**
72- * Override method inherited from `Overlay`
73- * to not close on position target click.
74- *
75- * @param {Event } _event
76- * @return {boolean }
77- * @protected
78- */
79- _shouldCloseOnOutsideClick ( event ) {
80- const eventPath = event . composedPath ( ) ;
81- return ! eventPath . includes ( this . positionTarget ) && ! eventPath . includes ( this ) ;
82- }
83-
84- _setOverlayWidth ( positionTarget , opened ) {
85- if ( positionTarget && opened ) {
86- const propPrefix = this . localName ;
87- this . style . setProperty ( `--_${ propPrefix } -default-width` , `${ positionTarget . clientWidth } px` ) ;
8852
89- const customWidth = getComputedStyle ( this . _comboBox ) . getPropertyValue ( `--${ propPrefix } -width` ) ;
90-
91- if ( customWidth === '' ) {
92- this . style . removeProperty ( `--${ propPrefix } -width` ) ;
93- } else {
94- this . style . setProperty ( `--${ propPrefix } -width` , customWidth ) ;
95- }
96-
97- this . _updatePosition ( ) ;
98- }
53+ return memoizedTemplate ;
9954 }
10055}
10156
0 commit comments