* fix(dialogs): kill horizontal overflow in dialogs and cut the worst modal copy Overflow hardening: - DialogTitle/DialogDescription and SheetTitle/SheetDescription get break-words at the primitive, so long unbroken interpolated strings (emails, product names, org numbers) can no longer widen any dialog. - AccountCombobox's non-flat dropdown is portaled to document.body with viewport-clamped geometry (new pure helper account-combobox-position.ts, unit-tested), the same fix info-tooltip.tsx applies to TooltipContent: the 34rem panel inside a scrollable DialogContent was the root cause of sideways-scrolling dialogs. Outside-click checks the portaled node, position tracks scroll/resize (capture phase), wheel/touchmove stop at the panel so react-remove-scroll's modal lock cannot block its scrolling, and DialogContent/SheetContent treat data-dialog-companion nodes as inside interactions so clicking the panel never dismisses the dialog. The flat variant is unchanged. - StrikeLinesDialog/CorrectionEntryDialog line rows switch bare 1fr grid tracks to minmax(0,1fr) and wrap the sm:contents-promoted AccountCombobox in a min-w-0 cell (SendInvoiceDialog's pattern). - New dialog-overflow-risk ratchet in no-new-antipatterns.mjs: bare fr tracks in dialog hosts, whitespace-nowrap inside DialogContent regions outside an allowlist, and unportaled >=20rem overlays; baselined at the post-fix 7 files. Copy reduction (convention 7, MatchVoucherDialog precedent): - New shared RattelseExplainer (HelpPopover) carries the "a posted verifikat cannot be edited directly" framing once; CorrectionEntryDialog, StrikeLinesDialog, RecordateEntryDialog and CorrectMetadataDialog drop their permanent inline explainer boxes and keep at most one sentence inline (hardcoded Swedish: verifikat surface). - SendInvoiceDialog keeps the actual addresses inline and moves the fixed CC/BCC framing plus the extra-address rules behind a HelpPopover (recipient_additional_hint replaced by recipient_help_fixed and recipient_help_additional in both messages files). - HelpPopover panels gain pointer-events-auto and the companion marker so they are actually interactive inside modal dialogs. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> * fix(bookkeeping): mechanism-accurate rattelse copy and calmer dropdown repositioning The shared RattelseExplainer claimed every rattelse is logged with who/when in the verifikat's rattelsehistorik, which is only true for the inline strike-and-replace track (StrikeLinesDialog, CorrectMetadataDialog). The storno dialogs (CorrectionEntryDialog, RecordateEntryDialog) never write that log: their BFL 5 kap 5 trail is the storno chain. The shared component now keeps only the universally true framing sentence, and each dialog's popover carries the trail sentence matching its own mechanism. AccountCombobox's capture-phase scroll/resize handler now skips setState when the recomputed position is shallow-equal to the current one (isSameDropdownPosition in the pure position helper, unit-tested) and ignores scroll events originating inside the portaled panel itself, so scrolling the account list no longer churns re-renders. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> --------- Co-authored-by: Jakob Wennberg <311770904+jakobwennberg-oss@users.noreply.github.com> Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
93 lines
3.2 KiB
TypeScript
93 lines
3.2 KiB
TypeScript
/**
|
|
* Pure positioning for AccountCombobox's portaled (non-flat) dropdown.
|
|
*
|
|
* The non-flat dropdown renders on document.body (see AccountCombobox) so a
|
|
* scrollable DialogContent can never clip it or grow a horizontal scrollbar
|
|
* around it. That trades CSS anchoring (absolute + top-full) for explicit
|
|
* viewport math, which lives here so it can be unit-tested headlessly.
|
|
*
|
|
* All numbers are CSS pixels in viewport coordinates (getBoundingClientRect
|
|
* space), matching position: fixed.
|
|
*/
|
|
|
|
export interface DropdownAnchorRect {
|
|
top: number
|
|
bottom: number
|
|
left: number
|
|
width: number
|
|
}
|
|
|
|
export interface DropdownViewportSize {
|
|
width: number
|
|
height: number
|
|
}
|
|
|
|
export interface DropdownPosition {
|
|
left: number
|
|
width: number
|
|
maxHeight: number
|
|
/** Set when the dropdown opens below the anchor (CSS `top`). */
|
|
top?: number
|
|
/**
|
|
* Set when the dropdown opens above the anchor (CSS `bottom`, measured from
|
|
* the viewport bottom). Anchoring by `bottom` lets the panel grow upward
|
|
* without knowing its own height.
|
|
*/
|
|
bottom?: number
|
|
}
|
|
|
|
/** 34rem: wide enough for account number + name + activation marker. */
|
|
export const DROPDOWN_PREFERRED_WIDTH = 544
|
|
/** Minimum gap kept between the dropdown and every viewport edge. */
|
|
export const DROPDOWN_VIEWPORT_MARGIN = 8
|
|
/** Gap between the anchor (trigger) and the dropdown. */
|
|
export const DROPDOWN_ANCHOR_GAP = 4
|
|
/** The dropdown's own scroll ceiling (was max-h-[300px] pre-portal). */
|
|
export const DROPDOWN_MAX_HEIGHT = 300
|
|
/** Below this much room the dropdown flips above the anchor instead. */
|
|
const MIN_USEFUL_HEIGHT = 120
|
|
/** Height floor so a cramped viewport still shows a scrollable list. */
|
|
const HEIGHT_FLOOR = 96
|
|
|
|
/**
|
|
* Shallow equality over the full position shape. The scroll/resize reposition
|
|
* handler uses this to skip setState when the recomputed geometry is
|
|
* unchanged (e.g. scroll events that did not move the anchor), so React does
|
|
* not re-render the open dropdown on every scroll tick.
|
|
*/
|
|
export function isSameDropdownPosition(
|
|
a: DropdownPosition | null,
|
|
b: DropdownPosition,
|
|
): boolean {
|
|
return (
|
|
a !== null &&
|
|
a.left === b.left &&
|
|
a.width === b.width &&
|
|
a.maxHeight === b.maxHeight &&
|
|
a.top === b.top &&
|
|
a.bottom === b.bottom
|
|
)
|
|
}
|
|
|
|
export function computeDropdownPosition(
|
|
anchor: DropdownAnchorRect,
|
|
viewport: DropdownViewportSize,
|
|
): DropdownPosition {
|
|
const margin = DROPDOWN_VIEWPORT_MARGIN
|
|
const maxWidth = Math.max(viewport.width - margin * 2, 0)
|
|
const width = Math.min(Math.max(anchor.width, DROPDOWN_PREFERRED_WIDTH), maxWidth)
|
|
const left = Math.max(margin, Math.min(anchor.left, viewport.width - width - margin))
|
|
|
|
const spaceBelow = viewport.height - anchor.bottom - DROPDOWN_ANCHOR_GAP - margin
|
|
const spaceAbove = anchor.top - DROPDOWN_ANCHOR_GAP - margin
|
|
const openUp = spaceBelow < MIN_USEFUL_HEIGHT && spaceAbove > spaceBelow
|
|
|
|
const available = openUp ? spaceAbove : spaceBelow
|
|
const maxHeight = Math.min(DROPDOWN_MAX_HEIGHT, Math.max(available, HEIGHT_FLOOR))
|
|
|
|
if (openUp) {
|
|
return { left, width, maxHeight, bottom: viewport.height - anchor.top + DROPDOWN_ANCHOR_GAP }
|
|
}
|
|
return { left, width, maxHeight, top: anchor.bottom + DROPDOWN_ANCHOR_GAP }
|
|
}
|