projects/wvr-elements/src/lib/wvr-dropdown/wvr-dropdown.component.ts
A dropdown with button and contextualized styling.
changeDetection | ChangeDetectionStrategy.Default |
selector | wvr-dropdown-component |
styleUrls | ./wvr-dropdown.component.scss |
templateUrl | ./wvr-dropdown.component.html |
constructor(injector: Injector, config: NgbDropdownConfig)
|
|||||||||
Parameters :
|
btnBackground | |
Type : string
|
|
Allows for override of button background value. |
btnBackgroundActive | |
Type : string
|
|
Allows for override of button background value in active state. |
btnBackgroundHover | |
Type : string
|
|
Allows for override of button background value in hover state. |
btnBorderActive | |
Type : string
|
|
Allows for override of button border value in active state. |
btnBorderColor | |
Type : string
|
|
Allows for override of button border color. |
btnBorderFocus | |
Type : string
|
|
Allows for override of button border value in focus state. |
btnBorderHover | |
Type : string
|
|
Allows for override of button border value in hover state. |
btnBorderRadius | |
Type : string
|
|
Allows for override the button radius. |
btnBoxShadowFocus | |
Type : string
|
|
Allows for override the button box shadow in focus state. |
btnColor | |
Type : string
|
|
Allows for override the button color. |
btnColorActive | |
Type : string
|
|
Allows for override the button color in active state. |
btnColorHover | |
Type : string
|
|
Allows for override the button color in hover state. |
btnCursor | |
Type : string
|
|
Allows for override the button cursor. |
btnFontFamily | |
Type : string
|
|
Allows for override the button font family. |
btnFontSize | |
Type : string
|
|
Allows for override the button font size. |
btnFontWeight | |
Type : string
|
|
Allows for override the button font weight. |
btnHref | |
Type : string
|
|
Default value : ''
|
|
Allows for override of button href value. |
btnLineHeight | |
Type : string
|
|
Allows for override the button line height. |
btnPadding | |
Type : string
|
|
Allows for override the button line height. |
btnSize | |
Type : string
|
|
Default value : ''
|
|
Allows for override of button size. |
btnTextAlign | |
Type : string
|
|
Allows for override the button line height. |
btnTextDecoration | |
Type : string
|
|
btnTextDecorationActive | |
Type : string
|
|
btnTextDecorationFocus | |
Type : string
|
|
btnTextDecorationHover | |
Type : string
|
|
btnType | |
Type : string
|
|
Allows for override the button type. |
btnVerticalAlign | |
Type : string
|
|
Allows for override the button line height. |
dropdownMenuDisplay | |
Type : string
|
|
Default value : 'dynamic'
|
|
menuAnimationSpeed | |
Type : number
|
|
A setter which sets the speed to |
menuBorder | |
Type : any
|
|
Binds the input from |
menuBorderDisplay | |
Type : any
|
|
Binds the input from |
menuBorderRadius | |
Type : any
|
|
Binds the input from |
menuFlexDirection | |
Type : any
|
|
Binds the input from |
menuItemMargin | |
Type : any
|
|
Binds the input from |
menuPadding | |
Type : any
|
|
Binds the input from |
menuThemeVariant | |
Type : ThemeVariantName
|
|
Binds the input from |
menuWidth | |
Type : any
|
|
Binds the input from |
menuXOffset | |
Type : any
|
|
Binds the input from |
menuYOffset | |
Type : any
|
|
Binds the input from |
openDelay | |
Type : number
|
|
Default value : 150
|
|
This establishes a delay in milliseconds before the dropdown is displayed. Do not set this too low as there may be problems with the focusIn and click events (click event may trigger or be triggered by a focusIn). |
placement | |
Type : string
|
|
Default value : 'top-right'
|
|
role | |
Type : string
|
|
Allows for override of role value (such as setting role="menu"). |
themeVariant | |
Type : ThemeVariantName
|
|
Default value : 'secondary'
|
|
Inherited from
WvrBaseComponent
|
|
Defined in
WvrBaseComponent:108
|
|
Allows for the visual customization of the dropdown menu activation button. |
toggleOn | |
Type : "click" | "mouseover"
|
|
Default value : 'click'
|
|
Configures the event type which will activate the dropdown menu. |
animate | |
Type : string
|
|
Inherited from
WvrBaseComponent
|
|
Defined in
WvrBaseComponent:68
|
|
A setter which parses a json string describing animation instructions and stores the derived object in |
animateConfig | |
Type : string
|
|
Inherited from
WvrBaseComponent
|
|
Defined in
WvrBaseComponent:76
|
|
A setter which parses a json string describing animation setting and stores the derived object in |
animateId | |
Type : string
|
|
Inherited from
WvrBaseComponent
|
|
Defined in
WvrBaseComponent:84
|
|
An attribute input allowing for the designation of an animation identifier for the purpose of animation targeting. |
animateTarget | |
Type : string
|
|
Inherited from
WvrBaseComponent
|
|
Defined in
WvrBaseComponent:87
|
|
An attribute input allowing for the designation of an animation target for animation events. |
hiddenInMobile | |
Type : boolean
|
|
Default value : false
|
|
Inherited from
WvrBaseComponent
|
|
Defined in
WvrBaseComponent:107
|
|
An attribute input specifying if this component should be hidden in the mobile layout. |
ngBindings | |
Type : string
|
|
Inherited from
WvrBaseComponent
|
|
Defined in
WvrBaseComponent:116
|
wvrData | |
Type : string
|
|
Inherited from
WvrBaseComponent
|
|
Defined in
WvrBaseComponent:45
|
wvrTheme | |
Type : string
|
|
Inherited from
WvrBaseComponent
|
|
Defined in
WvrBaseComponent:50
|
|
Allows for the override of theme for the particular component. |
animationEventTrigger | |
Type : EventEmitter
|
|
Inherited from
WvrBaseComponent
|
|
Defined in
WvrBaseComponent:110
|
|
An Output biding used for triggering animations. |
style.--wvr-dropdown-menu-animation-speed |
Type : any
|
Binds the value of the animationspeed in seconds to the css variable |
class.wvr-bootstrap |
Type : boolean
|
Default value : true
|
Inherited from
WvrBaseComponent
|
Defined in
WvrBaseComponent:58
|
A host binding used to ensure the presense of the |
class.wvr-hidden |
Type : boolean
|
Inherited from
WvrBaseComponent
|
Defined in
WvrBaseComponent:102
|
A host bound accessor which applies the wvr-hidden class if both isMobileLayout and hiddenInMobile evaluate to true. |
style |
Type : any
|
Inherited from
WvrBaseComponent
|
Defined in
WvrBaseComponent:60
|
focusin |
Arguments : '$event'
|
focusin($event: Event)
|
A handler method for the |
focusout |
Arguments : '$event'
|
focusout($event: Event)
|
A handler method for the The 'relatedTarget' may be null if the focus lost is due to the focus leaving the web browser itself rather than the element within the page. In this case, do not remove focus because the what goes on outside of the page should not affect what goes inside the page. |
keydown |
Arguments : '$event'
|
keydown($event)
|
A single handler method for when the any key is down while associated with the host element. |
mouseenter |
Arguments : '$event'
|
mouseenter($event: Event)
|
A handler method for the Opens the dropdown if |
mouseleave |
Arguments : '$event'
|
mouseleave($event: Event)
|
A handler method for the Closes the dropdown if |
documentClick | ||||||
documentClick($event: MouseEvent)
|
||||||
Decorators :
@HostListener('document:mousedown', ['$event'])
|
||||||
A handler method for the Closes the dropdown if The event.button == 0 is the left click or the un-initialized state. The 'mousedown' is used instead of 'click' to avoid bubbling problems. The 'click' does not happen before 'focusin' and there is a race condition between the two. When 'mousedown' is used, it happens before 'focusin' and the bubbling can be blocked to avoid a race condition.
Parameters :
Returns :
void
|
focusIn | ||||||
focusIn($event: Event)
|
||||||
Decorators :
@HostListener('focusin', ['$event'])
|
||||||
A handler method for the
Parameters :
Returns :
void
|
focusOut | ||||||
focusOut($event: Event)
|
||||||
Decorators :
@HostListener('focusout', ['$event'])
|
||||||
A handler method for the The 'relatedTarget' may be null if the focus lost is due to the focus leaving the web browser itself rather than the element within the page. In this case, do not remove focus because the what goes on outside of the page should not affect what goes inside the page.
Parameters :
Returns :
void
|
Private focusToChild |
focusToChild(focused: number, up: boolean, list: any)
|
Change focus to a non-disabled child based on the current focused position within the list.
Returns :
void
|
Private focusToToggle |
focusToToggle()
|
Change focus to the drop down toggle that exists outside of the drop down list.
Returns :
void
|
Private giveFocus |
giveFocus()
|
If focus is not set, then set focus. Does open dropdown, if it is closed and not already in the process of opening.
Returns :
void
|
hoverClose | ||||||
hoverClose($event: Event)
|
||||||
Decorators :
@HostListener('mouseleave', ['$event'])
|
||||||
A handler method for the Closes the dropdown if
Parameters :
Returns :
void
|
hoverOpen | ||||||
hoverOpen($event: Event)
|
||||||
Decorators :
@HostListener('mouseenter', ['$event'])
|
||||||
A handler method for the Opens the dropdown if
Parameters :
Returns :
void
|
isOpen |
isOpen()
|
An access method to expose the
Returns :
boolean
|
keyDown | ||||
keyDown($event)
|
||||
Decorators :
@HostListener('keydown', ['$event'])
|
||||
A single handler method for when the any key is down while associated with the host element.
Parameters :
Returns :
void
|
ngAfterViewInit |
ngAfterViewInit()
|
Called after the view has been intialized. Handles the rendering of the projected content.
Returns :
void
|
Private takeFocus |
takeFocus()
|
If focus is set, then unset focus. Does close dropdown, if it is open.
Returns :
void
|
applyThemeOverride |
applyThemeOverride(customProperty: string, value: string)
|
Inherited from
WvrBaseComponent
|
Defined in
WvrBaseComponent:237
|
Returns :
void
|
bootstrapNgBindings |
bootstrapNgBindings()
|
Inherited from
WvrBaseComponent
|
Defined in
WvrBaseComponent:175
|
Returns :
void
|
getWvrData |
getWvrData()
|
Inherited from
WvrBaseComponent
|
Defined in
WvrBaseComponent:262
|
Returns :
string
|
hasWvrData |
hasWvrData()
|
Inherited from
WvrBaseComponent
|
Defined in
WvrBaseComponent:258
|
Returns :
boolean
|
initializeAnimationElement |
initializeAnimationElement()
|
Inherited from
WvrBaseComponent
|
Defined in
WvrBaseComponent:267
|
Returns :
void
|
initializeAnimationRegistration |
initializeAnimationRegistration()
|
Inherited from
WvrBaseComponent
|
Defined in
WvrBaseComponent:273
|
Returns :
void
|
ngAfterContentInit |
ngAfterContentInit()
|
Inherited from
WvrBaseComponent
|
Defined in
WvrBaseComponent:160
|
Used for post content initialization animation setup.
Returns :
void
|
ngOnDestroy |
ngOnDestroy()
|
Inherited from
WvrBaseComponent
|
Defined in
WvrBaseComponent:166
|
Handles the the unregistering of this component with the component registry.
Returns :
void
|
ngOnInit |
ngOnInit()
|
Inherited from
WvrBaseComponent
|
Defined in
WvrBaseComponent:145
|
Used to setup this component for animating.
Returns :
void
|
onAnimationEvent | ||||||
onAnimationEvent($event: Event)
|
||||||
Inherited from
WvrBaseComponent
|
||||||
Defined in
WvrBaseComponent:290
|
||||||
Trigger's the animation specified by the incoming event.
Parameters :
Returns :
void
|
Private processData |
processData()
|
Inherited from
WvrBaseComponent
|
Defined in
WvrBaseComponent:295
|
Returns :
void
|
triggerAnimations | ||||||
triggerAnimations(animationTriggerType: string)
|
||||||
Inherited from
WvrBaseComponent
|
||||||
Defined in
WvrBaseComponent:244
|
||||||
Plays the animation specified by the incoming animation trigger.
Parameters :
Returns :
void
|
Private _btnTextDecoration |
Type : string
|
Allows for override the button text decoration. |
Private _btnTextDecorationActive |
Type : string
|
Allows for override the button text decoration. |
Private _btnTextDecorationFocus |
Type : string
|
Private _btnTextDecorationHover |
Type : string
|
Private _openDelayTimer |
Type : NodeJS.Timeout
|
animationSpeedSeconds |
Decorators :
@HostBinding('style.--wvr-dropdown-menu-animation-speed')
|
Binds the value of the animationspeed in seconds to the css variable |
dropdown |
Type : NgbDropdown
|
Decorators :
@ViewChild(NgbDropdown)
|
Sets asside a reference to the NgbDropdown element. |
focus |
Default value : false
|
A state used to represent that focus is on or within the element. Used for button navigation decisions. |
open |
Default value : false
|
A public access reference to the open/closed state of the dropdown menu. Used for animations; |
Private requestClose |
Default value : false
|
Designate that a close has been requested. Used to inform that the popup should be closed while the popup is still in the process of opening up. |
Private _animationConfig |
Type : any
|
Default value : {}
|
Inherited from
WvrBaseComponent
|
Defined in
WvrBaseComponent:73
|
An object representation of the settings specifying the specific behavior of the animation for this component. |
Private Readonly _animationService |
Type : AnimationService<WvrBaseComponent>
|
Inherited from
WvrBaseComponent
|
Defined in
WvrBaseComponent:93
|
A reference to the AnimationService |
Private _animationSettings |
Type : any
|
Default value : {}
|
Inherited from
WvrBaseComponent
|
Defined in
WvrBaseComponent:65
|
An object representation of the animation instructions for this component. |
Private _ngBindings |
Type : literal type
|
Inherited from
WvrBaseComponent
|
Defined in
WvrBaseComponent:114
|
animationRootElem |
Type : ElementRef
|
Decorators :
@ViewChild('animationRoot')
|
Inherited from
WvrBaseComponent
|
Defined in
WvrBaseComponent:90
|
A view child of the template element containing the #animationRoot identifier. |
Private animationStateId |
Type : number
|
Inherited from
WvrBaseComponent
|
Defined in
WvrBaseComponent:81
|
An identifier used to access the animation state for this component. |
Readonly appConfig |
Type : AppConfig
|
Inherited from
WvrBaseComponent
|
Defined in
WvrBaseComponent:37
|
A reference to the AppConfig |
Readonly cdRef |
Type : ChangeDetectorRef
|
Inherited from
WvrBaseComponent
|
Defined in
WvrBaseComponent:34
|
A reference to the ChangeDetectorRef |
Readonly componentRegistry |
Type : ComponentRegistryService<WvrBaseComponent>
|
Inherited from
WvrBaseComponent
|
Defined in
WvrBaseComponent:25
|
A reference to the ComponentRegistryService |
data |
Type : literal type
|
Default value : {}
|
Inherited from
WvrBaseComponent
|
Defined in
WvrBaseComponent:42
|
Readonly eRef |
Type : ElementRef
|
Inherited from
WvrBaseComponent
|
Defined in
WvrBaseComponent:31
|
A reference to the ElementRef |
Readonly id |
Type : number
|
Inherited from
WvrBaseComponent
|
Defined in
WvrBaseComponent:28
|
A generated unique identifier for this comonent. |
isMobile |
Type : Observable<boolean>
|
Inherited from
WvrBaseComponent
|
Defined in
WvrBaseComponent:120
|
isMobileLayout |
Type : boolean
|
Inherited from
WvrBaseComponent
|
Defined in
WvrBaseComponent:112
|
Private Readonly kebabize |
Default value : () => {...}
|
Inherited from
WvrBaseComponent
|
Defined in
WvrBaseComponent:321
|
Private Readonly ngBindingsService |
Type : NgBindingsService
|
Inherited from
WvrBaseComponent
|
Defined in
WvrBaseComponent:99
|
A reference to the NgBindingsService |
Readonly store |
Type : Store<RootState>
|
Inherited from
WvrBaseComponent
|
Defined in
WvrBaseComponent:40
|
A reference to the Store |
style |
Decorators :
@HostBinding('style')
|
Inherited from
WvrBaseComponent
|
Defined in
WvrBaseComponent:60
|
Protected subscriptions |
Type : Array<Subscription>
|
Inherited from
WvrBaseComponent
|
Defined in
WvrBaseComponent:122
|
themeOverrides |
Type : object
|
Default value : {}
|
Inherited from
WvrBaseComponent
|
Defined in
WvrBaseComponent:47
|
Private Readonly themeService |
Type : ThemeService
|
Inherited from
WvrBaseComponent
|
Defined in
WvrBaseComponent:96
|
A reference to the ThemeService |
variantTypes |
Type : []
|
Default value : []
|
Inherited from
WvrBaseComponent
|
Defined in
WvrBaseComponent:62
|
wvrBootstrap |
Default value : true
|
Decorators :
@HostBinding('class.wvr-bootstrap')
|
Inherited from
WvrBaseComponent
|
Defined in
WvrBaseComponent:58
|
A host binding used to ensure the presense of the |
menuAnimationSpeed | ||||||
setmenuAnimationSpeed(speed: number)
|
||||||
A setter which sets the speed to
Parameters :
Returns :
void
|
btnTextDecoration | ||||||
getbtnTextDecoration()
|
||||||
setbtnTextDecoration(value: string)
|
||||||
Parameters :
Returns :
void
|
btnTextDecorationActive | ||||||
getbtnTextDecorationActive()
|
||||||
setbtnTextDecorationActive(value: string)
|
||||||
Parameters :
Returns :
void
|
btnTextDecorationFocus | ||||||
getbtnTextDecorationFocus()
|
||||||
setbtnTextDecorationFocus(value: string)
|
||||||
Parameters :
Returns :
void
|
btnTextDecorationHover | ||||||
getbtnTextDecorationHover()
|
||||||
setbtnTextDecorationHover(value: string)
|
||||||
Parameters :
Returns :
void
|
import { AfterViewInit, ChangeDetectionStrategy, Component, HostBinding, HostListener, Injector, Input, ViewChild } from '@angular/core';
import { NgbDropdown, NgbDropdownConfig } from '@ng-bootstrap/ng-bootstrap';
import { ThemeVariantName } from '../shared/theme';
import { projectContent } from '../shared/utility/projection.utility';
import { WvrBaseComponent } from '../shared/wvr-base.component';
/**
* A dropdown with button and contextualized styling.
*/
@Component({
selector: 'wvr-dropdown-component',
templateUrl: './wvr-dropdown.component.html',
styleUrls: ['./wvr-dropdown.component.scss'],
changeDetection: ChangeDetectionStrategy.Default
})
export class WvrDropdownComponent extends WvrBaseComponent implements AfterViewInit {
/** Sets asside a reference to the NgbDropdown element. */
@ViewChild(NgbDropdown) dropdown: NgbDropdown;
/** Binds the value of the animationspeed in seconds to the css variable `--wvr-dropdown-menu-animation-speed` */
@HostBinding('style.--wvr-dropdown-menu-animation-speed') animationSpeedSeconds;
/**
* This establishes a delay in milliseconds before the dropdown is displayed.
*
* Do not set this too low as there may be problems with the focusIn and click events (click event may trigger or be triggered by a focusIn).
*/
@Input() openDelay = 150;
private _openDelayTimer: NodeJS.Timeout;
/** A setter which sets the speed to `_animationSpeedSeconds` in seconds. */
@Input() set menuAnimationSpeed(speed: number) {
this.animationSpeedSeconds = `${speed / 1000}s`;
}
/** Allows for override of button background value. */
@Input() btnBackground: string;
/** Allows for override of button background value in active state. */
@Input() btnBackgroundActive: string;
/** Allows for override of button background value in hover state. */
@Input() btnBackgroundHover: string;
/** Allows for override of button border value in active state. */
@Input() btnBorderActive: string;
/** Allows for override of button border color. */
@Input() btnBorderColor: string;
/** Allows for override of button border value in focus state. */
@Input() btnBorderFocus: string;
/** Allows for override of button border value in hover state. */
@Input() btnBorderHover: string;
/** Allows for override the button color. */
@Input() btnColor: string;
/** Allows for override the button color in active state. */
@Input() btnColorActive: string;
/** Allows for override the button color in hover state. */
@Input() btnColorHover: string;
/** Allows for override the button radius. */
@Input() btnBorderRadius: string;
/** Allows for override the button box shadow in focus state. */
@Input() btnBoxShadowFocus: string;
/** Allows for override the button cursor. */
@Input() btnCursor: string;
/** Allows for override the button font family. */
@Input() btnFontFamily: string;
/** Allows for override the button font size. */
@Input() btnFontSize: string;
/** Allows for override the button font weight. */
@Input() btnFontWeight: string;
/** Allows for override the button line height. */
@Input() btnLineHeight: string;
/** Allows for override the button line height. */
@Input() btnPadding: string;
/** Allows for override the button line height. */
@Input() btnTextAlign: string;
/** Allows for override the button type. */
@Input() btnType: string;
/** Allows for override the button line height. */
@Input() btnVerticalAlign: string;
/** Allows for override of button href value. */
@Input() btnHref = '';
/** Allows for override of button size. */
@Input() btnSize = '';
/** Allows for the visual customization of the dropdown menu activation button. */
@Input() themeVariant: ThemeVariantName = 'secondary';
/** Binds the input from `menuBackground` to the css variable `--wvr-dropdown-menu-background` */
@Input() menuThemeVariant: ThemeVariantName;
/** Allows for override of role value (such as setting role="menu"). */
@Input() role: string;
/** Binds the input from `menu-border` to the css variable `--wvr-dropdown-menu-border` */
@HostBinding('style.--wvr-dropdown-menu-border') @Input() menuBorder;
/** Binds the input from `menu-border-radius` to the css variable `--wvr-dropdown-menu-border-radius` */
@HostBinding('style.--wvr-dropdown-menu-border-radius') @Input() menuBorderRadius;
/** Binds the input from `menu-border-display` to the css variable `--wvr-dropdown-menu-display` */
@HostBinding('style.--wvr-dropdown-menu-display') @Input() menuBorderDisplay;
/** Binds the input from `menu-border-flexDirection` to the css variable `--wvr-dropdown-menu-flex-direction` */
@HostBinding('style.--wvr-dropdown-menu-flex-direction') @Input() menuFlexDirection;
/** Binds the input from `menu-padding` to the css variable `--wvr-dropdown-menu-padding` */
@HostBinding('style.--wvr-dropdown-menu-padding') @Input() menuPadding;
/** Binds the input from `menu-width` to the css variable `--wvr-dropdown-menu-width` */
@HostBinding('style.--wvr-dropdown-menu-width') @Input() menuWidth;
/**
* Binds the input from `menu-x-offset` to the css variable `--wvr-dropdown-x-offset`.
* This css variable is applied by `left` css rule to the menu.
*/
@HostBinding('style.--wvr-dropdown-menu-x-offset') @Input() menuXOffset;
/**
* Binds the input from `menu-y-offset` to the css variable `--wvr-dropdown-y-offset`.
* This css variable is applied by `margin-top` css rule to the menu.
*/
@HostBinding('style.--wvr-dropdown-menu-y-offset') @Input() menuYOffset;
/**
* Binds the input from `item-margin` to the css variable `--wvr-dropdown-item-margin`.
* This css variable is applied by both the `[wvre-dropdown-menu-item]` and the `wvre-dropdown-menu-item`
* css rules to each item passed to the the dropdown menu.
*/
@HostBinding('style.--wvr-dropdown-menu-item-margin') @Input() menuItemMargin;
/** Configures the event type which will activate the dropdown menu. */
@Input() toggleOn: 'click' | 'mouseover' = 'click';
/** Allows for override the button text decoration. */
private _btnTextDecoration: string;
@Input() set btnTextDecoration(value: string) {
this._btnTextDecoration = value;
}
get btnTextDecoration(): string {
return this._btnTextDecoration ?
this._btnTextDecoration :
`var(--wvr-btn-${this.themeVariant}-text-decoration-default)`;
}
/** Allows for override the button text decoration. */
private _btnTextDecorationActive: string;
@Input() set btnTextDecorationActive(value: string) {
this._btnTextDecorationActive = value;
}
get btnTextDecorationActive(): string {
return this._btnTextDecorationActive ?
this._btnTextDecorationActive :
`var(--wvr-btn-${this.themeVariant}-active-text-decoration-default)`;
}
// text-decoration-focus
private _btnTextDecorationFocus: string;
@Input() set btnTextDecorationFocus(value: string) {
this._btnTextDecorationFocus = value;
}
get btnTextDecorationFocus(): string {
return this._btnTextDecorationFocus ?
this._btnTextDecorationFocus :
`var(--wvr-btn-${this.themeVariant}-focus-text-decoration-default)`;
}
private _btnTextDecorationHover: string;
@Input() set btnTextDecorationHover(value: string) {
this._btnTextDecorationHover = value;
}
get btnTextDecorationHover(): string {
return this._btnTextDecorationHover ?
this._btnTextDecorationHover :
`var(--wvr-btn-${this.themeVariant}-hover-text-decoration-default)`;
}
@Input() placement = 'top-right';
/**
* A public access reference to the open/closed state of the dropdown menu. Used for
* animations;
*/
open = false;
/**
* A state used to represent that focus is on or within the element.
* Used for button navigation decisions.
*/
focus = false;
/**
* Designate that a close has been requested.
*
* Used to inform that the popup should be closed while the popup is still in the process of opening up.
*/
private requestClose = false;
@Input() dropdownMenuDisplay = 'dynamic';
constructor(injector: Injector, config: NgbDropdownConfig) {
super(injector);
config.autoClose = false;
}
/** Called after the view has been intialized. Handles the rendering of the projected content. */
ngAfterViewInit(): void {
projectContent(this.eRef, 'template[dropdown-button]', 'span[button-content]');
projectContent(this.eRef, 'template[dropdown-menu]', 'div[dropdown-menu]');
}
/** An access method to expose the `isOpen` utility method from `NgbDropdown` */
isOpen(): boolean {
return this.dropdown ? this.dropdown.isOpen() : false;
}
/**
* A handler method for the `focus` event.
*/
@HostListener('focusin', ['$event']) focusIn($event: Event): void {
if (this.eRef.nativeElement.contains($event.target)) {
if (!this.focus) {
$event.stopPropagation();
$event.preventDefault();
this.giveFocus();
}
} else {
this.takeFocus();
}
}
/**
* A handler method for the `focus` event.
*
* The 'relatedTarget' may be null if the focus lost is due to the focus leaving the web browser itself rather than the element within the page.
* In this case, do not remove focus because the what goes on outside of the page should not affect what goes inside the page.
*/
@HostListener('focusout', ['$event']) focusOut($event: Event): void {
if ($event['relatedTarget'] !== null) {
if (!this.eRef.nativeElement.contains($event['relatedTarget'])) {
this.takeFocus();
}
}
}
/**
* A handler method for the `mouseenter` event.
*
* Opens the dropdown if `toggleOn` is set to `mouseover`.
*/
@HostListener('mouseenter', ['$event']) hoverOpen($event: Event): void {
if (this.toggleOn === 'mouseover') {
this.giveFocus();
}
}
/**
* A handler method for the `mouseleave` event.
*
* Closes the dropdown if `toggleOn` is set to `mouseover`.
*/
@HostListener('mouseleave', ['$event']) hoverClose($event: Event): void {
if (this.toggleOn === 'mouseover') {
this.takeFocus();
}
}
/**
* A handler method for the `document:mousedown` event.
*
* Closes the dropdown if `toggleOn` is set to `click`
* And the click occured off of the wvre-dropdown component.
*
* The event.button == 0 is the left click or the un-initialized state.
*
* The 'mousedown' is used instead of 'click' to avoid bubbling problems.
* The 'click' does not happen before 'focusin' and there is a race condition between the two.
* When 'mousedown' is used, it happens before 'focusin' and the bubbling can be blocked to avoid a race condition.
*/
@HostListener('document:mousedown', ['$event']) documentClick($event: MouseEvent): void {
if ($event.button == 0) {
const dropDownButton = this.eRef.nativeElement.querySelector(".wvr-dropdown > div > wvr-button-component");
if (!!dropDownButton && !!dropDownButton.nativeElement && !!$event.target) {
if (dropDownButton.nativeElement.contains($event.target)) {
if (this.toggleOn === 'click') {
$event.stopPropagation();
$event.preventDefault();
if (this.isOpen()) {
this.takeFocus();
} else {
this.giveFocus();
}
}
} else {
this.takeFocus();
}
}
}
}
/**
* A single handler method for when the any key is down while associated with the host element.
*/
@HostListener('keydown', ['$event']) keyDown($event): void {
const lowerKey = $event.key.toLowerCase();
if (lowerKey == "escape") {
if (this.isOpen()) {
const list = this.eRef.nativeElement.querySelector('.dropdown-menu > *');
$event.stopPropagation();
$event.preventDefault();
if (!!list && list.contains($event.target)) {
this.focusToToggle();
} else {
this.takeFocus();
}
}
}
else if (lowerKey == "space") {
const list = this.eRef.nativeElement.querySelector('.dropdown-menu > *');
if (!!list && list.contains($event.target)) {
// @todo
} else {
$event.stopPropagation();
$event.preventDefault();
if (this.isOpen()) {
this.takeFocus();
} else {
this.giveFocus();
}
}
}
else if (lowerKey == "arrowup" || lowerKey == "arrowdown") {
const list = this.eRef.nativeElement.querySelector('.dropdown-menu > *');
if (!!list) {
const up = lowerKey == "arrowup";
$event.stopPropagation();
$event.preventDefault();
if (list.contains($event.target)) {
let focused = list.children.length;
for (let i = 0; i < list.children.length; i++) {
if ($event.target == list.children[i]) {
focused = i;
}
}
this.focusToChild(focused, up, list);
}
else if (list.children.length > 0) {
const focused = up ? list.children.length - 1 : -1;
this.focusToChild(focused, up, list);
}
}
}
}
/** Change focus to the drop down toggle that exists outside of the drop down list. */
private focusToToggle() {
const dropdown = this.eRef.nativeElement.querySelector('.dropdown .dropdown-toggle .wvr-button');
if (!!dropdown) {
dropdown.focus();
}
}
/** Change focus to a non-disabled child based on the current focused position within the list. */
private focusToChild(focused: number, up: boolean, list: any): void {
if (focused == list.children.length || up && focused == 0 || !up && focused == list.children.length) {
this.focusToToggle();
} else {
let i = up ? focused - 1 : focused + 1;
// Select the first non-disabled child.
if (up) {
for (; i >= 0; i--) {
if (!list.children[i].hasAttribute('disabled')) {
break;
}
// There is no available child to move to, so set out of range.
if (i == 0) {
i = list.children.length;
break;
}
}
} else {
for (; i < list.children.length; i++) {
if (!list.children[i].hasAttribute('disabled')) {
break;
}
}
}
if (i == list.children.length) {
this.focusToToggle();
} else {
list.children[i].focus();
}
}
}
/**
* If focus is not set, then set focus.
*
* Does open dropdown, if it is closed and not already in the process of opening.
*/
private giveFocus(): void {
if (!this._openDelayTimer && !this.focus) {
this.focus = true;
this.requestClose = false;
this._openDelayTimer = setTimeout(() => {
if (this.focus) {
if (!this.requestClose && !this.isMobileLayout) {
this.open = true;
this.dropdown.open();
}
this._openDelayTimer = undefined;
}
this.requestClose = false;
}, this.openDelay);
}
};
/**
* If focus is set, then unset focus.
*
* Does close dropdown, if it is open.
*/
private takeFocus(): void {
if (!!this._openDelayTimer) {
this.requestClose = true;
} else if (this.focus) {
this.focus = false;
if (this.isOpen()) {
this.open = false;
this.dropdown.close();
}
}
};
}
<div #WvrDropdown class="wvr-components wvr-dropdown d-inline-flex align-items-center">
<div ngbDropdown display="{{dropdownMenuDisplay}}" class="d-inline-block">
<wvr-button-component
[background]="btnBackground"
[backgroundActive]="btnBackgroundActive"
[backgroundHover]="btnBackgroundHover"
[borderColor]="btnBorderColor"
[borderActive]="btnBorderActive"
[borderHover]="btnBorderHover"
[borderFocus]="btnBorderFocus"
[borderRadius]="btnBorderRadius"
[boxShadowFocus]="btnBoxShadowFocus"
[themeVariant]="themeVariant"
[btnSize]="btnSize"
[color]="btnColor"
[btnType]="btnType"
[colorActive]="btnColorActive"
[colorHover]="btnColorHover"
[cursor]="btnCursor"
[fontFamily]="btnFontFamily"
[fontSize]="btnFontSize"
[fontWeight]="btnFontWeight"
[href]="btnHref"
[lineHeight]="btnLineHeight"
[padding]="btnPadding"
[role]="role"
[textAlign]="btnTextAlign"
[textDecoration]="btnTextDecoration"
[textDecorationActive]="btnTextDecorationActive"
[textDecorationFocus]="btnTextDecorationFocus"
[textDecorationHover]="btnTextDecorationHover"
[verticalAlign]="btnVerticalAlign" ngbDropdownAnchor>
<template button-content>
<ng-content select="template[dropdown-button]"></ng-content>
</template>
</wvr-button-component>
<div ngbDropdownMenu dropdown-menu [ngClass]="{open: open,closed: !open}" class="bg-{{menuThemeVariant}}"></div>
</div>
</div>
<ng-content select="template[dropdown-menu]"></ng-content>
./wvr-dropdown.component.scss
@import "../shared/styles/variables";
:host {
@extend .variables;
--wvr-dropdown-menu-animation-speed: 0.25s;
--wvr-dropdown-menu-border: 1px solid var(--wvr-gray-dark);
--wvr-dropdown-menu-border-radius: 6px;
--wvr-dropdown-menu-display: flex;
--wvr-dropdown-menu-flex-direction: column;
--wvr-dropdown-menu-padding: 25px;
--wvr-dropdown-menu-width: fit-content;
--wvr-dropdown-menu-x-offset: 0px;
--wvr-dropdown-menu-y-offset: -6px;
--wvr-dropdown-menu-item-margin: 0 0 10px 0;
}
.wvr-dropdown {
font-family: var(--wvr-font-family-sans-serif);
position: relative;
.dropdown-toggle::after {
display:none;
}
wvr-button-component {
position: relative;
z-index: 1001;
}
[ngbDropdownMenu] {
border: var(--wvr-dropdown-menu-border);
border-radius: var(--wvr-dropdown-menu-border-radius);
left: var(--wvr-dropdown-menu-x-offset) !important;
top: var(--wvr-dropdown-menu-y-offset) !important;
padding: var(--wvr-dropdown-menu-padding);
position: absolute;
width: var(--wvr-dropdown-menu-width);
z-index: 1200;
}
.open {
animation: openDD var(--wvr-dropdown-menu-animation-speed) ease-in-out;
}
@keyframes openDD {
0% { visibility:hidden; opacity: 0; }
100% { visibility:visible; opacity: 1; }
}
.closed {
animation: closeDD var(--wvr-dropdown-menu-animation-speed) ease-in-out;
visibility:hidden;
}
@keyframes closeDD {
0% { opacity: 1; visibility: visible; }
100% { opacity: 0; visibility:hidden; }
}
}