-
Notifications
You must be signed in to change notification settings - Fork 83
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add custom CSS property to customize select overlay width (#7578)
- Loading branch information
1 parent
2e5bf2a
commit 580f225
Showing
7 changed files
with
106 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/** | ||
* @license | ||
* Copyright (c) 2017 - 2024 Vaadin Ltd. | ||
* This program is available under Apache License Version 2.0, available at https://vaadin.com/license/ | ||
*/ | ||
import { DirMixin } from '@vaadin/component-base/src/dir-mixin.js'; | ||
import { OverlayMixin } from '@vaadin/overlay/src/vaadin-overlay-mixin.js'; | ||
import { PositionMixin } from '@vaadin/overlay/src/vaadin-overlay-position-mixin.js'; | ||
|
||
/** | ||
* @polymerMixin | ||
* @mixes DirMixin | ||
* @mixes OverlayMixin | ||
* @mixes PositionMixin | ||
*/ | ||
export const SelectOverlayMixin = (superClass) => | ||
class SelectOverlayMixin extends PositionMixin(OverlayMixin(DirMixin(superClass))) { | ||
static get observers() { | ||
return ['_updateOverlayWidth(opened, owner)']; | ||
} | ||
|
||
/** @protected */ | ||
_getMenuElement() { | ||
return Array.from(this.children).find((el) => el.localName !== 'style'); | ||
} | ||
|
||
/** @private */ | ||
_updateOverlayWidth(opened, owner) { | ||
if (opened && owner) { | ||
const widthProperty = '--vaadin-select-overlay-width'; | ||
const customWidth = getComputedStyle(owner).getPropertyValue(widthProperty); | ||
|
||
if (customWidth === '') { | ||
this.style.removeProperty(widthProperty); | ||
} else { | ||
this.style.setProperty(widthProperty, customWidth); | ||
} | ||
} | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters