524 lines
71 KiB
JavaScript
524 lines
71 KiB
JavaScript
|
|
import { ContentChild, ContentChildren, Directive, EventEmitter, forwardRef, Inject, Input, Output, } from '@angular/core';
|
||
|
|
import { DOCUMENT } from '@angular/common';
|
||
|
|
import { fromEvent, Subject } from 'rxjs';
|
||
|
|
import { take } from 'rxjs/operators';
|
||
|
|
import { ngbPositioning } from '../util/positioning';
|
||
|
|
import { addPopperOffset } from '../util/positioning-util';
|
||
|
|
import { ngbAutoClose } from '../util/autoclose';
|
||
|
|
import { Key } from '../util/key';
|
||
|
|
import { FOCUSABLE_ELEMENTS_SELECTOR } from '../util/focus-trap';
|
||
|
|
import * as i0 from "@angular/core";
|
||
|
|
import * as i1 from "./dropdown-config";
|
||
|
|
/**
|
||
|
|
* @deprecated 14.2.0 this directive isn't useful anymore. You can remove it from your imports
|
||
|
|
*/
|
||
|
|
export class NgbNavbar {
|
||
|
|
}
|
||
|
|
NgbNavbar.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.0.0", ngImport: i0, type: NgbNavbar, deps: [], target: i0.ɵɵFactoryTarget.Directive });
|
||
|
|
NgbNavbar.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "15.0.0", type: NgbNavbar, isStandalone: true, selector: ".navbar", ngImport: i0 });
|
||
|
|
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.0.0", ngImport: i0, type: NgbNavbar, decorators: [{
|
||
|
|
type: Directive,
|
||
|
|
args: [{ selector: '.navbar', standalone: true }]
|
||
|
|
}] });
|
||
|
|
/**
|
||
|
|
* A directive you should put on a dropdown item to enable keyboard navigation.
|
||
|
|
* Arrow keys will move focus between items marked with this directive.
|
||
|
|
*
|
||
|
|
* @since 4.1.0
|
||
|
|
*/
|
||
|
|
export class NgbDropdownItem {
|
||
|
|
constructor(elementRef, _renderer) {
|
||
|
|
this.elementRef = elementRef;
|
||
|
|
this._renderer = _renderer;
|
||
|
|
this._disabled = false;
|
||
|
|
}
|
||
|
|
set disabled(value) {
|
||
|
|
this._disabled = value === '' || value === true; // accept an empty attribute as true
|
||
|
|
// note: we don't use a host binding for disabled because when used on links, it fails because links don't have a
|
||
|
|
// disabled property
|
||
|
|
// setting the property using the renderer, OTOH, works fine in both cases.
|
||
|
|
this._renderer.setProperty(this.elementRef.nativeElement, 'disabled', this._disabled);
|
||
|
|
}
|
||
|
|
get disabled() {
|
||
|
|
return this._disabled;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
NgbDropdownItem.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.0.0", ngImport: i0, type: NgbDropdownItem, deps: [{ token: i0.ElementRef }, { token: i0.Renderer2 }], target: i0.ɵɵFactoryTarget.Directive });
|
||
|
|
NgbDropdownItem.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "15.0.0", type: NgbDropdownItem, isStandalone: true, selector: "[ngbDropdownItem]", inputs: { disabled: "disabled" }, host: { properties: { "class.disabled": "disabled", "tabIndex": "disabled ? -1 : 0" }, classAttribute: "dropdown-item" }, ngImport: i0 });
|
||
|
|
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.0.0", ngImport: i0, type: NgbDropdownItem, decorators: [{
|
||
|
|
type: Directive,
|
||
|
|
args: [{
|
||
|
|
selector: '[ngbDropdownItem]',
|
||
|
|
standalone: true,
|
||
|
|
host: { class: 'dropdown-item', '[class.disabled]': 'disabled', '[tabIndex]': 'disabled ? -1 : 0' },
|
||
|
|
}]
|
||
|
|
}], ctorParameters: function () { return [{ type: i0.ElementRef }, { type: i0.Renderer2 }]; }, propDecorators: { disabled: [{
|
||
|
|
type: Input
|
||
|
|
}] } });
|
||
|
|
/**
|
||
|
|
* A directive that wraps dropdown menu content and dropdown items.
|
||
|
|
*/
|
||
|
|
export class NgbDropdownMenu {
|
||
|
|
constructor(dropdown, _elementRef) {
|
||
|
|
this.dropdown = dropdown;
|
||
|
|
this.placement = 'bottom';
|
||
|
|
this.isOpen = false;
|
||
|
|
this.nativeElement = _elementRef.nativeElement;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
NgbDropdownMenu.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.0.0", ngImport: i0, type: NgbDropdownMenu, deps: [{ token: forwardRef(() => NgbDropdown) }, { token: i0.ElementRef }], target: i0.ɵɵFactoryTarget.Directive });
|
||
|
|
NgbDropdownMenu.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "15.0.0", type: NgbDropdownMenu, isStandalone: true, selector: "[ngbDropdownMenu]", host: { listeners: { "keydown.ArrowUp": "dropdown.onKeyDown($event)", "keydown.ArrowDown": "dropdown.onKeyDown($event)", "keydown.Home": "dropdown.onKeyDown($event)", "keydown.End": "dropdown.onKeyDown($event)", "keydown.Enter": "dropdown.onKeyDown($event)", "keydown.Space": "dropdown.onKeyDown($event)", "keydown.Tab": "dropdown.onKeyDown($event)", "keydown.Shift.Tab": "dropdown.onKeyDown($event)" }, properties: { "class.dropdown-menu": "true", "class.show": "dropdown.isOpen()" } }, queries: [{ propertyName: "menuItems", predicate: NgbDropdownItem }], ngImport: i0 });
|
||
|
|
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.0.0", ngImport: i0, type: NgbDropdownMenu, decorators: [{
|
||
|
|
type: Directive,
|
||
|
|
args: [{
|
||
|
|
selector: '[ngbDropdownMenu]',
|
||
|
|
standalone: true,
|
||
|
|
host: {
|
||
|
|
'[class.dropdown-menu]': 'true',
|
||
|
|
'[class.show]': 'dropdown.isOpen()',
|
||
|
|
'(keydown.ArrowUp)': 'dropdown.onKeyDown($event)',
|
||
|
|
'(keydown.ArrowDown)': 'dropdown.onKeyDown($event)',
|
||
|
|
'(keydown.Home)': 'dropdown.onKeyDown($event)',
|
||
|
|
'(keydown.End)': 'dropdown.onKeyDown($event)',
|
||
|
|
'(keydown.Enter)': 'dropdown.onKeyDown($event)',
|
||
|
|
'(keydown.Space)': 'dropdown.onKeyDown($event)',
|
||
|
|
'(keydown.Tab)': 'dropdown.onKeyDown($event)',
|
||
|
|
'(keydown.Shift.Tab)': 'dropdown.onKeyDown($event)',
|
||
|
|
},
|
||
|
|
}]
|
||
|
|
}], ctorParameters: function () { return [{ type: NgbDropdown, decorators: [{
|
||
|
|
type: Inject,
|
||
|
|
args: [forwardRef(() => NgbDropdown)]
|
||
|
|
}] }, { type: i0.ElementRef }]; }, propDecorators: { menuItems: [{
|
||
|
|
type: ContentChildren,
|
||
|
|
args: [NgbDropdownItem]
|
||
|
|
}] } });
|
||
|
|
/**
|
||
|
|
* A directive to mark an element to which dropdown menu will be anchored.
|
||
|
|
*
|
||
|
|
* This is a simple version of the `NgbDropdownToggle` directive.
|
||
|
|
* It plays the same role, but doesn't listen to click events to toggle dropdown menu thus enabling support
|
||
|
|
* for events other than click.
|
||
|
|
*
|
||
|
|
* @since 1.1.0
|
||
|
|
*/
|
||
|
|
export class NgbDropdownAnchor {
|
||
|
|
constructor(dropdown, _elementRef) {
|
||
|
|
this.dropdown = dropdown;
|
||
|
|
this.nativeElement = _elementRef.nativeElement;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
NgbDropdownAnchor.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.0.0", ngImport: i0, type: NgbDropdownAnchor, deps: [{ token: forwardRef(() => NgbDropdown) }, { token: i0.ElementRef }], target: i0.ɵɵFactoryTarget.Directive });
|
||
|
|
NgbDropdownAnchor.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "15.0.0", type: NgbDropdownAnchor, isStandalone: true, selector: "[ngbDropdownAnchor]", host: { properties: { "attr.aria-expanded": "dropdown.isOpen()" }, classAttribute: "dropdown-toggle" }, ngImport: i0 });
|
||
|
|
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.0.0", ngImport: i0, type: NgbDropdownAnchor, decorators: [{
|
||
|
|
type: Directive,
|
||
|
|
args: [{
|
||
|
|
selector: '[ngbDropdownAnchor]',
|
||
|
|
standalone: true,
|
||
|
|
host: { class: 'dropdown-toggle', '[attr.aria-expanded]': 'dropdown.isOpen()' },
|
||
|
|
}]
|
||
|
|
}], ctorParameters: function () { return [{ type: NgbDropdown, decorators: [{
|
||
|
|
type: Inject,
|
||
|
|
args: [forwardRef(() => NgbDropdown)]
|
||
|
|
}] }, { type: i0.ElementRef }]; } });
|
||
|
|
/**
|
||
|
|
* A directive to mark an element that will toggle dropdown via the `click` event.
|
||
|
|
*
|
||
|
|
* You can also use `NgbDropdownAnchor` as an alternative.
|
||
|
|
*/
|
||
|
|
export class NgbDropdownToggle extends NgbDropdownAnchor {
|
||
|
|
constructor(dropdown, elementRef) {
|
||
|
|
super(dropdown, elementRef);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
NgbDropdownToggle.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.0.0", ngImport: i0, type: NgbDropdownToggle, deps: [{ token: forwardRef(() => NgbDropdown) }, { token: i0.ElementRef }], target: i0.ɵɵFactoryTarget.Directive });
|
||
|
|
NgbDropdownToggle.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "15.0.0", type: NgbDropdownToggle, isStandalone: true, selector: "[ngbDropdownToggle]", host: { listeners: { "click": "dropdown.toggle()", "keydown.ArrowUp": "dropdown.onKeyDown($event)", "keydown.ArrowDown": "dropdown.onKeyDown($event)", "keydown.Home": "dropdown.onKeyDown($event)", "keydown.End": "dropdown.onKeyDown($event)", "keydown.Tab": "dropdown.onKeyDown($event)", "keydown.Shift.Tab": "dropdown.onKeyDown($event)" }, properties: { "attr.aria-expanded": "dropdown.isOpen()" }, classAttribute: "dropdown-toggle" }, providers: [{ provide: NgbDropdownAnchor, useExisting: forwardRef(() => NgbDropdownToggle) }], usesInheritance: true, ngImport: i0 });
|
||
|
|
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.0.0", ngImport: i0, type: NgbDropdownToggle, decorators: [{
|
||
|
|
type: Directive,
|
||
|
|
args: [{
|
||
|
|
selector: '[ngbDropdownToggle]',
|
||
|
|
standalone: true,
|
||
|
|
host: {
|
||
|
|
class: 'dropdown-toggle',
|
||
|
|
'[attr.aria-expanded]': 'dropdown.isOpen()',
|
||
|
|
'(click)': 'dropdown.toggle()',
|
||
|
|
'(keydown.ArrowUp)': 'dropdown.onKeyDown($event)',
|
||
|
|
'(keydown.ArrowDown)': 'dropdown.onKeyDown($event)',
|
||
|
|
'(keydown.Home)': 'dropdown.onKeyDown($event)',
|
||
|
|
'(keydown.End)': 'dropdown.onKeyDown($event)',
|
||
|
|
'(keydown.Tab)': 'dropdown.onKeyDown($event)',
|
||
|
|
'(keydown.Shift.Tab)': 'dropdown.onKeyDown($event)',
|
||
|
|
},
|
||
|
|
providers: [{ provide: NgbDropdownAnchor, useExisting: forwardRef(() => NgbDropdownToggle) }],
|
||
|
|
}]
|
||
|
|
}], ctorParameters: function () { return [{ type: NgbDropdown, decorators: [{
|
||
|
|
type: Inject,
|
||
|
|
args: [forwardRef(() => NgbDropdown)]
|
||
|
|
}] }, { type: i0.ElementRef }]; } });
|
||
|
|
/**
|
||
|
|
* A directive that provides contextual overlays for displaying lists of links and more.
|
||
|
|
*/
|
||
|
|
export class NgbDropdown {
|
||
|
|
constructor(_changeDetector, config, _document, _ngZone, _elementRef, _renderer) {
|
||
|
|
this._changeDetector = _changeDetector;
|
||
|
|
this._document = _document;
|
||
|
|
this._ngZone = _ngZone;
|
||
|
|
this._elementRef = _elementRef;
|
||
|
|
this._renderer = _renderer;
|
||
|
|
this._destroyCloseHandlers$ = new Subject();
|
||
|
|
this._bodyContainer = null;
|
||
|
|
/**
|
||
|
|
* Defines whether or not the dropdown menu is opened initially.
|
||
|
|
*/
|
||
|
|
this._open = false;
|
||
|
|
/**
|
||
|
|
* An event fired when the dropdown is opened or closed.
|
||
|
|
*
|
||
|
|
* The event payload is a `boolean`:
|
||
|
|
* * `true` - the dropdown was opened
|
||
|
|
* * `false` - the dropdown was closed
|
||
|
|
*/
|
||
|
|
this.openChange = new EventEmitter();
|
||
|
|
this.placement = config.placement;
|
||
|
|
this.popperOptions = config.popperOptions;
|
||
|
|
this.container = config.container;
|
||
|
|
this.autoClose = config.autoClose;
|
||
|
|
this._positioning = ngbPositioning();
|
||
|
|
this.display = this._elementRef.nativeElement.closest('.navbar') ? 'static' : 'dynamic';
|
||
|
|
}
|
||
|
|
ngAfterContentInit() {
|
||
|
|
this._ngZone.onStable.pipe(take(1)).subscribe(() => {
|
||
|
|
this._applyPlacementClasses();
|
||
|
|
if (this._open) {
|
||
|
|
this._setCloseHandlers();
|
||
|
|
}
|
||
|
|
});
|
||
|
|
}
|
||
|
|
ngOnChanges(changes) {
|
||
|
|
if (changes.container && this._open) {
|
||
|
|
this._applyContainer(this.container);
|
||
|
|
}
|
||
|
|
if (changes.placement && !changes.placement.firstChange) {
|
||
|
|
this._positioning.setOptions({
|
||
|
|
hostElement: this._anchor.nativeElement,
|
||
|
|
targetElement: this._bodyContainer || this._menu.nativeElement,
|
||
|
|
placement: this.placement,
|
||
|
|
appendToBody: this.container === 'body',
|
||
|
|
});
|
||
|
|
this._applyPlacementClasses();
|
||
|
|
}
|
||
|
|
if (changes.dropdownClass) {
|
||
|
|
const { currentValue, previousValue } = changes.dropdownClass;
|
||
|
|
this._applyCustomDropdownClass(currentValue, previousValue);
|
||
|
|
}
|
||
|
|
if (changes.autoClose && this._open) {
|
||
|
|
this.autoClose = changes.autoClose.currentValue;
|
||
|
|
this._setCloseHandlers();
|
||
|
|
}
|
||
|
|
}
|
||
|
|
/**
|
||
|
|
* Checks if the dropdown menu is open.
|
||
|
|
*/
|
||
|
|
isOpen() {
|
||
|
|
return this._open;
|
||
|
|
}
|
||
|
|
/**
|
||
|
|
* Opens the dropdown menu.
|
||
|
|
*/
|
||
|
|
open() {
|
||
|
|
if (!this._open) {
|
||
|
|
this._open = true;
|
||
|
|
this._applyContainer(this.container);
|
||
|
|
this.openChange.emit(true);
|
||
|
|
this._setCloseHandlers();
|
||
|
|
if (this._anchor) {
|
||
|
|
this._anchor.nativeElement.focus();
|
||
|
|
if (this.display === 'dynamic') {
|
||
|
|
this._ngZone.runOutsideAngular(() => {
|
||
|
|
this._positioning.createPopper({
|
||
|
|
hostElement: this._anchor.nativeElement,
|
||
|
|
targetElement: this._bodyContainer || this._menu.nativeElement,
|
||
|
|
placement: this.placement,
|
||
|
|
appendToBody: this.container === 'body',
|
||
|
|
updatePopperOptions: (options) => this.popperOptions(addPopperOffset([0, 2])(options)),
|
||
|
|
});
|
||
|
|
this._applyPlacementClasses();
|
||
|
|
this._zoneSubscription = this._ngZone.onStable.subscribe(() => this._positionMenu());
|
||
|
|
});
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
_setCloseHandlers() {
|
||
|
|
this._destroyCloseHandlers$.next(); // destroy any existing close handlers
|
||
|
|
ngbAutoClose(this._ngZone, this._document, this.autoClose, (source) => {
|
||
|
|
this.close();
|
||
|
|
if (source === 0 /* SOURCE.ESCAPE */) {
|
||
|
|
this._anchor.nativeElement.focus();
|
||
|
|
}
|
||
|
|
}, this._destroyCloseHandlers$, this._menu ? [this._menu.nativeElement] : [], this._anchor ? [this._anchor.nativeElement] : [], '.dropdown-item,.dropdown-divider');
|
||
|
|
}
|
||
|
|
/**
|
||
|
|
* Closes the dropdown menu.
|
||
|
|
*/
|
||
|
|
close() {
|
||
|
|
if (this._open) {
|
||
|
|
this._open = false;
|
||
|
|
this._resetContainer();
|
||
|
|
this._positioning.destroy();
|
||
|
|
this._zoneSubscription?.unsubscribe();
|
||
|
|
this._destroyCloseHandlers$.next();
|
||
|
|
this.openChange.emit(false);
|
||
|
|
this._changeDetector.markForCheck();
|
||
|
|
}
|
||
|
|
}
|
||
|
|
/**
|
||
|
|
* Toggles the dropdown menu.
|
||
|
|
*/
|
||
|
|
toggle() {
|
||
|
|
if (this.isOpen()) {
|
||
|
|
this.close();
|
||
|
|
}
|
||
|
|
else {
|
||
|
|
this.open();
|
||
|
|
}
|
||
|
|
}
|
||
|
|
ngOnDestroy() {
|
||
|
|
this.close();
|
||
|
|
}
|
||
|
|
onKeyDown(event) {
|
||
|
|
/* eslint-disable-next-line deprecation/deprecation */
|
||
|
|
const key = event.which;
|
||
|
|
const itemElements = this._getMenuElements();
|
||
|
|
let position = -1;
|
||
|
|
let itemElement = null;
|
||
|
|
const isEventFromToggle = this._isEventFromToggle(event);
|
||
|
|
if (!isEventFromToggle && itemElements.length) {
|
||
|
|
itemElements.forEach((item, index) => {
|
||
|
|
if (item.contains(event.target)) {
|
||
|
|
itemElement = item;
|
||
|
|
}
|
||
|
|
if (item === this._document.activeElement) {
|
||
|
|
position = index;
|
||
|
|
}
|
||
|
|
});
|
||
|
|
}
|
||
|
|
// closing on Enter / Space
|
||
|
|
if (key === Key.Space || key === Key.Enter) {
|
||
|
|
if (itemElement && (this.autoClose === true || this.autoClose === 'inside')) {
|
||
|
|
// Item is either a button or a link, so click will be triggered by the browser on Enter or Space.
|
||
|
|
// So we have to register a one-time click handler that will fire after any user defined click handlers
|
||
|
|
// to close the dropdown
|
||
|
|
fromEvent(itemElement, 'click')
|
||
|
|
.pipe(take(1))
|
||
|
|
.subscribe(() => this.close());
|
||
|
|
}
|
||
|
|
return;
|
||
|
|
}
|
||
|
|
if (key === Key.Tab) {
|
||
|
|
if (event.target && this.isOpen() && this.autoClose) {
|
||
|
|
if (this._anchor.nativeElement === event.target) {
|
||
|
|
if (this.container === 'body' && !event.shiftKey) {
|
||
|
|
/* This case is special: user is using [Tab] from the anchor/toggle.
|
||
|
|
User expects the next focusable element in the dropdown menu to get focus.
|
||
|
|
But the menu is not a sibling to anchor/toggle, it is at the end of the body.
|
||
|
|
Trick is to synchronously focus the menu element, and let the [keydown.Tab] go
|
||
|
|
so that browser will focus the proper element (first one focusable in the menu) */
|
||
|
|
this._renderer.setAttribute(this._menu.nativeElement, 'tabindex', '0');
|
||
|
|
this._menu.nativeElement.focus();
|
||
|
|
this._renderer.removeAttribute(this._menu.nativeElement, 'tabindex');
|
||
|
|
}
|
||
|
|
else if (event.shiftKey) {
|
||
|
|
this.close();
|
||
|
|
}
|
||
|
|
return;
|
||
|
|
}
|
||
|
|
else if (this.container === 'body') {
|
||
|
|
const focusableElements = this._menu.nativeElement.querySelectorAll(FOCUSABLE_ELEMENTS_SELECTOR);
|
||
|
|
if (event.shiftKey && event.target === focusableElements[0]) {
|
||
|
|
this._anchor.nativeElement.focus();
|
||
|
|
event.preventDefault();
|
||
|
|
}
|
||
|
|
else if (!event.shiftKey && event.target === focusableElements[focusableElements.length - 1]) {
|
||
|
|
this._anchor.nativeElement.focus();
|
||
|
|
this.close();
|
||
|
|
}
|
||
|
|
}
|
||
|
|
else {
|
||
|
|
fromEvent(event.target, 'focusout')
|
||
|
|
.pipe(take(1))
|
||
|
|
.subscribe(({ relatedTarget }) => {
|
||
|
|
if (!this._elementRef.nativeElement.contains(relatedTarget)) {
|
||
|
|
this.close();
|
||
|
|
}
|
||
|
|
});
|
||
|
|
}
|
||
|
|
}
|
||
|
|
return;
|
||
|
|
}
|
||
|
|
// opening / navigating
|
||
|
|
if (isEventFromToggle || itemElement) {
|
||
|
|
this.open();
|
||
|
|
if (itemElements.length) {
|
||
|
|
switch (key) {
|
||
|
|
case Key.ArrowDown:
|
||
|
|
position = Math.min(position + 1, itemElements.length - 1);
|
||
|
|
break;
|
||
|
|
case Key.ArrowUp:
|
||
|
|
if (this._isDropup() && position === -1) {
|
||
|
|
position = itemElements.length - 1;
|
||
|
|
break;
|
||
|
|
}
|
||
|
|
position = Math.max(position - 1, 0);
|
||
|
|
break;
|
||
|
|
case Key.Home:
|
||
|
|
position = 0;
|
||
|
|
break;
|
||
|
|
case Key.End:
|
||
|
|
position = itemElements.length - 1;
|
||
|
|
break;
|
||
|
|
}
|
||
|
|
itemElements[position].focus();
|
||
|
|
}
|
||
|
|
event.preventDefault();
|
||
|
|
}
|
||
|
|
}
|
||
|
|
_isDropup() {
|
||
|
|
return this._elementRef.nativeElement.classList.contains('dropup');
|
||
|
|
}
|
||
|
|
_isEventFromToggle(event) {
|
||
|
|
return this._anchor.nativeElement.contains(event.target);
|
||
|
|
}
|
||
|
|
_getMenuElements() {
|
||
|
|
const menu = this._menu;
|
||
|
|
if (menu == null) {
|
||
|
|
return [];
|
||
|
|
}
|
||
|
|
return menu.menuItems.filter((item) => !item.disabled).map((item) => item.elementRef.nativeElement);
|
||
|
|
}
|
||
|
|
_positionMenu() {
|
||
|
|
const menu = this._menu;
|
||
|
|
if (this.isOpen() && menu) {
|
||
|
|
if (this.display === 'dynamic') {
|
||
|
|
this._positioning.update();
|
||
|
|
this._applyPlacementClasses();
|
||
|
|
}
|
||
|
|
else {
|
||
|
|
this._applyPlacementClasses(this._getFirstPlacement(this.placement));
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
_getFirstPlacement(placement) {
|
||
|
|
return Array.isArray(placement) ? placement[0] : placement.split(' ')[0];
|
||
|
|
}
|
||
|
|
_resetContainer() {
|
||
|
|
const renderer = this._renderer;
|
||
|
|
if (this._menu) {
|
||
|
|
const dropdownElement = this._elementRef.nativeElement;
|
||
|
|
const dropdownMenuElement = this._menu.nativeElement;
|
||
|
|
renderer.appendChild(dropdownElement, dropdownMenuElement);
|
||
|
|
}
|
||
|
|
if (this._bodyContainer) {
|
||
|
|
renderer.removeChild(this._document.body, this._bodyContainer);
|
||
|
|
this._bodyContainer = null;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
_applyContainer(container = null) {
|
||
|
|
this._resetContainer();
|
||
|
|
if (container === 'body') {
|
||
|
|
const renderer = this._renderer;
|
||
|
|
const dropdownMenuElement = this._menu.nativeElement;
|
||
|
|
const bodyContainer = (this._bodyContainer = this._bodyContainer || renderer.createElement('div'));
|
||
|
|
// Override some styles to have the positioning working
|
||
|
|
renderer.setStyle(bodyContainer, 'position', 'absolute');
|
||
|
|
renderer.setStyle(dropdownMenuElement, 'position', 'static');
|
||
|
|
renderer.setStyle(bodyContainer, 'z-index', '1055');
|
||
|
|
renderer.appendChild(bodyContainer, dropdownMenuElement);
|
||
|
|
renderer.appendChild(this._document.body, bodyContainer);
|
||
|
|
}
|
||
|
|
this._applyCustomDropdownClass(this.dropdownClass);
|
||
|
|
}
|
||
|
|
_applyCustomDropdownClass(newClass, oldClass) {
|
||
|
|
const targetElement = this.container === 'body' ? this._bodyContainer : this._elementRef.nativeElement;
|
||
|
|
if (targetElement) {
|
||
|
|
if (oldClass) {
|
||
|
|
this._renderer.removeClass(targetElement, oldClass);
|
||
|
|
}
|
||
|
|
if (newClass) {
|
||
|
|
this._renderer.addClass(targetElement, newClass);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
_applyPlacementClasses(placement) {
|
||
|
|
const menu = this._menu;
|
||
|
|
if (menu) {
|
||
|
|
if (!placement) {
|
||
|
|
placement = this._getFirstPlacement(this.placement);
|
||
|
|
}
|
||
|
|
const renderer = this._renderer;
|
||
|
|
const dropdownElement = this._elementRef.nativeElement;
|
||
|
|
// remove the current placement classes
|
||
|
|
renderer.removeClass(dropdownElement, 'dropup');
|
||
|
|
renderer.removeClass(dropdownElement, 'dropdown');
|
||
|
|
const { nativeElement } = menu;
|
||
|
|
if (this.display === 'static') {
|
||
|
|
menu.placement = null;
|
||
|
|
renderer.setAttribute(nativeElement, 'data-bs-popper', 'static');
|
||
|
|
}
|
||
|
|
else {
|
||
|
|
menu.placement = placement;
|
||
|
|
renderer.removeAttribute(nativeElement, 'data-bs-popper');
|
||
|
|
}
|
||
|
|
/*
|
||
|
|
* apply the new placement
|
||
|
|
* in case of top use up-arrow or down-arrow otherwise
|
||
|
|
*/
|
||
|
|
const dropdownClass = placement.search('^top') !== -1 ? 'dropup' : 'dropdown';
|
||
|
|
renderer.addClass(dropdownElement, dropdownClass);
|
||
|
|
const bodyContainer = this._bodyContainer;
|
||
|
|
if (bodyContainer) {
|
||
|
|
renderer.removeClass(bodyContainer, 'dropup');
|
||
|
|
renderer.removeClass(bodyContainer, 'dropdown');
|
||
|
|
renderer.addClass(bodyContainer, dropdownClass);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
NgbDropdown.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.0.0", ngImport: i0, type: NgbDropdown, deps: [{ token: i0.ChangeDetectorRef }, { token: i1.NgbDropdownConfig }, { token: DOCUMENT }, { token: i0.NgZone }, { token: i0.ElementRef }, { token: i0.Renderer2 }], target: i0.ɵɵFactoryTarget.Directive });
|
||
|
|
NgbDropdown.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "15.0.0", type: NgbDropdown, isStandalone: true, selector: "[ngbDropdown]", inputs: { autoClose: "autoClose", dropdownClass: "dropdownClass", _open: ["open", "_open"], placement: "placement", popperOptions: "popperOptions", container: "container", display: "display" }, outputs: { openChange: "openChange" }, host: { properties: { "class.show": "isOpen()" } }, queries: [{ propertyName: "_menu", first: true, predicate: NgbDropdownMenu, descendants: true }, { propertyName: "_anchor", first: true, predicate: NgbDropdownAnchor, descendants: true }], exportAs: ["ngbDropdown"], usesOnChanges: true, ngImport: i0 });
|
||
|
|
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.0.0", ngImport: i0, type: NgbDropdown, decorators: [{
|
||
|
|
type: Directive,
|
||
|
|
args: [{
|
||
|
|
selector: '[ngbDropdown]',
|
||
|
|
exportAs: 'ngbDropdown',
|
||
|
|
standalone: true,
|
||
|
|
host: { '[class.show]': 'isOpen()' },
|
||
|
|
}]
|
||
|
|
}], ctorParameters: function () { return [{ type: i0.ChangeDetectorRef }, { type: i1.NgbDropdownConfig }, { type: undefined, decorators: [{
|
||
|
|
type: Inject,
|
||
|
|
args: [DOCUMENT]
|
||
|
|
}] }, { type: i0.NgZone }, { type: i0.ElementRef }, { type: i0.Renderer2 }]; }, propDecorators: { _menu: [{
|
||
|
|
type: ContentChild,
|
||
|
|
args: [NgbDropdownMenu, { static: false }]
|
||
|
|
}], _anchor: [{
|
||
|
|
type: ContentChild,
|
||
|
|
args: [NgbDropdownAnchor, { static: false }]
|
||
|
|
}], autoClose: [{
|
||
|
|
type: Input
|
||
|
|
}], dropdownClass: [{
|
||
|
|
type: Input
|
||
|
|
}], _open: [{
|
||
|
|
type: Input,
|
||
|
|
args: ['open']
|
||
|
|
}], placement: [{
|
||
|
|
type: Input
|
||
|
|
}], popperOptions: [{
|
||
|
|
type: Input
|
||
|
|
}], container: [{
|
||
|
|
type: Input
|
||
|
|
}], display: [{
|
||
|
|
type: Input
|
||
|
|
}], openChange: [{
|
||
|
|
type: Output
|
||
|
|
}] } });
|
||
|
|
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiZHJvcGRvd24uanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi8uLi8uLi9zcmMvZHJvcGRvd24vZHJvcGRvd24udHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUEsT0FBTyxFQUdOLFlBQVksRUFDWixlQUFlLEVBQ2YsU0FBUyxFQUVULFlBQVksRUFDWixVQUFVLEVBQ1YsTUFBTSxFQUNOLEtBQUssRUFJTCxNQUFNLEdBSU4sTUFBTSxlQUFlLENBQUM7QUFDdkIsT0FBTyxFQUFFLFFBQVEsRUFBRSxNQUFNLGlCQUFpQixDQUFDO0FBQzNDLE9BQU8sRUFBRSxTQUFTLEVBQUUsT0FBTyxFQUFnQixNQUFNLE1BQU0sQ0FBQztBQUN4RCxPQUFPLEVBQUUsSUFBSSxFQUFFLE1BQU0sZ0JBQWdCLENBQUM7QUFFdEMsT0FBTyxFQUFFLGNBQWMsRUFBNkIsTUFBTSxxQkFBcUIsQ0FBQztBQUVoRixPQUFPLEVBQUUsZUFBZSxFQUFFLE1BQU0sMEJBQTBCLENBQUM7QUFDM0QsT0FBTyxFQUFFLFlBQVksRUFBVSxNQU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