mn-angular-lib 2.0.22 → 2.0.23
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -3923,12 +3923,18 @@ class MnDropdown {
|
|
|
3923
3923
|
* rendered by mn-bottom-sheet instead, so it needs no branch here.
|
|
3924
3924
|
*/
|
|
3925
3925
|
get panelClasses() {
|
|
3926
|
-
const base = 'fixed z-9999 min-w-48 max-w-[min(20rem,90vw)] bg-base-100 border border-base-300 rounded-md shadow-lg py-1 max-h-[60vh]
|
|
3926
|
+
const base = 'fixed z-9999 min-w-48 max-w-[min(20rem,90vw)] bg-base-100 border border-base-300 rounded-md shadow-lg py-1 max-h-[60vh]' +
|
|
3927
|
+
(this.alignStart ? '' : ' -translate-x-full');
|
|
3927
3928
|
return this.isSearchable ? `${base} flex flex-col overflow-hidden` : `${base} overflow-auto`;
|
|
3928
3929
|
}
|
|
3929
3930
|
/** Tailwind's `sm` breakpoint — below this the menu renders as a bottom sheet.
|
|
3930
3931
|
* Kept in step with the same constant in mn-bottom-sheet / mn-multi-select. */
|
|
3931
3932
|
static SHEET_MAX_WIDTH = 639.98;
|
|
3933
|
+
/**
|
|
3934
|
+
* Whether the popover opens rightwards from the trigger's left edge instead of leftwards from
|
|
3935
|
+
* its right edge. Set by {@link fitIntoViewport} when there is no room on the left.
|
|
3936
|
+
*/
|
|
3937
|
+
alignStart = false;
|
|
3932
3938
|
/** The anchored popover panel currently moved into `document.body`, if any. */
|
|
3933
3939
|
movedPanel = null;
|
|
3934
3940
|
/** The bottom-sheet host, for outside-click tests. The sheet owns its own placement. */
|
|
@@ -3994,6 +4000,8 @@ class MnDropdown {
|
|
|
3994
4000
|
set dropdownRef(ref) {
|
|
3995
4001
|
const el = ref?.nativeElement ?? null;
|
|
3996
4002
|
this.movedPanel = this.portal(el, this.movedPanel);
|
|
4003
|
+
if (el)
|
|
4004
|
+
this.fitIntoViewport(el);
|
|
3997
4005
|
if (el)
|
|
3998
4006
|
this.focusPendingItem();
|
|
3999
4007
|
if (el && this.isSearchable) {
|
|
@@ -4264,6 +4272,7 @@ class MnDropdown {
|
|
|
4264
4272
|
updateDropdownPosition() {
|
|
4265
4273
|
if (!this.triggerRef)
|
|
4266
4274
|
return;
|
|
4275
|
+
this.alignStart = false;
|
|
4267
4276
|
const rect = this.triggerRef.nativeElement.getBoundingClientRect();
|
|
4268
4277
|
// The panel is right-aligned to the trigger via a `-translate-x-full` class, so
|
|
4269
4278
|
// `left` is anchored to the trigger's right edge.
|
|
@@ -4274,6 +4283,32 @@ class MnDropdown {
|
|
|
4274
4283
|
left: `${rect.right}px`,
|
|
4275
4284
|
};
|
|
4276
4285
|
}
|
|
4286
|
+
/**
|
|
4287
|
+
* Keeps the opened popover inside the window. It normally hangs leftwards from the trigger's
|
|
4288
|
+
* right edge; near the left edge of the window that pushed it off-screen, so it then opens
|
|
4289
|
+
* rightwards from the trigger's left edge instead, and it never comes closer than 8 px to
|
|
4290
|
+
* either edge. Applied to the element directly as well as to the bound state, in the same pass
|
|
4291
|
+
* the panel appears, so no frame is drawn off-screen first.
|
|
4292
|
+
* @param panel The popover panel, already in the document with its content.
|
|
4293
|
+
*/
|
|
4294
|
+
fitIntoViewport(panel) {
|
|
4295
|
+
const trigger = this.triggerRef?.nativeElement;
|
|
4296
|
+
if (!trigger || typeof window === 'undefined')
|
|
4297
|
+
return;
|
|
4298
|
+
const margin = 8;
|
|
4299
|
+
const rect = trigger.getBoundingClientRect();
|
|
4300
|
+
const width = panel.offsetWidth;
|
|
4301
|
+
// The usable width: innerWidth would count a page scrollbar as room.
|
|
4302
|
+
const viewport = document.documentElement.clientWidth || window.innerWidth;
|
|
4303
|
+
const alignStart = rect.right - width < margin;
|
|
4304
|
+
const left = alignStart
|
|
4305
|
+
? Math.max(margin, Math.min(rect.left, viewport - width - margin))
|
|
4306
|
+
: Math.min(rect.right, viewport - margin);
|
|
4307
|
+
this.alignStart = alignStart;
|
|
4308
|
+
this.dropdownStyle = { ...this.dropdownStyle, left: `${left}px` };
|
|
4309
|
+
panel.style.left = `${left}px`;
|
|
4310
|
+
panel.classList.toggle('-translate-x-full', !alignStart);
|
|
4311
|
+
}
|
|
4277
4312
|
startWatchingTrigger() {
|
|
4278
4313
|
this.stopWatchingTrigger();
|
|
4279
4314
|
const trigger = this.triggerRef?.nativeElement;
|