@open-mercato/ui 0.10.1-develop.8123.1.acf6ca6db8 → 0.10.1-develop.8126.1.ccf499ef4c
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.
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@open-mercato/ui",
|
|
3
|
-
"version": "0.10.1-develop.
|
|
3
|
+
"version": "0.10.1-develop.8126.1.ccf499ef4c",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -156,14 +156,14 @@
|
|
|
156
156
|
"remark-gfm": "^4.0.1"
|
|
157
157
|
},
|
|
158
158
|
"peerDependencies": {
|
|
159
|
-
"@open-mercato/shared": "0.10.1-develop.
|
|
159
|
+
"@open-mercato/shared": "0.10.1-develop.8126.1.ccf499ef4c",
|
|
160
160
|
"react": ">=18.0.0",
|
|
161
161
|
"react-dom": ">=18.0.0",
|
|
162
162
|
"react-is": ">=18.0.0"
|
|
163
163
|
},
|
|
164
164
|
"devDependencies": {
|
|
165
165
|
"@figma/code-connect": "^1.3.4",
|
|
166
|
-
"@open-mercato/shared": "0.10.1-develop.
|
|
166
|
+
"@open-mercato/shared": "0.10.1-develop.8126.1.ccf499ef4c",
|
|
167
167
|
"@testing-library/dom": "^10.4.1",
|
|
168
168
|
"@testing-library/jest-dom": "^7.0.1",
|
|
169
169
|
"@testing-library/react": "^16.3.3",
|
package/src/backend/CrudForm.tsx
CHANGED
|
@@ -145,6 +145,19 @@ function evaluateFieldVisibility(
|
|
|
145
145
|
return values[visibleWhen.field] === visibleWhen.equals
|
|
146
146
|
}
|
|
147
147
|
|
|
148
|
+
function isVerticalScrollContainer(element: Element): boolean {
|
|
149
|
+
const { overflowY } = window.getComputedStyle(element)
|
|
150
|
+
return overflowY === 'auto' || overflowY === 'scroll'
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
function isScrolledByPaddedDialog(root: HTMLElement, dialog: HTMLElement): boolean {
|
|
154
|
+
for (let node: HTMLElement | null = root; node && node !== dialog; node = node.parentElement) {
|
|
155
|
+
if (isVerticalScrollContainer(node)) return false
|
|
156
|
+
}
|
|
157
|
+
if (!isVerticalScrollContainer(dialog)) return false
|
|
158
|
+
return Number.parseFloat(window.getComputedStyle(dialog).paddingBottom) > 0
|
|
159
|
+
}
|
|
160
|
+
|
|
148
161
|
function isFormControlTarget(target: EventTarget | null): boolean {
|
|
149
162
|
if (!target || typeof (target as Element).tagName !== 'string') return false
|
|
150
163
|
const el = target as HTMLElement
|
|
@@ -920,6 +933,7 @@ function CrudFormImpl<TValues extends Record<string, unknown>>({
|
|
|
920
933
|
const [customFieldDefsVersion, setCustomFieldDefsVersion] = React.useState(0)
|
|
921
934
|
const [fieldsetEditorTarget, setFieldsetEditorTarget] = React.useState<{ entityId: string; fieldsetCode: string | null; view: 'entity' | 'fieldset' } | null>(null)
|
|
922
935
|
const [isInDialog, setIsInDialog] = React.useState(false)
|
|
936
|
+
const [scrolledByPaddedDialog, setScrolledByPaddedDialog] = React.useState(false)
|
|
923
937
|
const rootRef = React.useRef<HTMLDivElement | null>(null)
|
|
924
938
|
|
|
925
939
|
// Collapsible groups support
|
|
@@ -1464,11 +1478,23 @@ function CrudFormImpl<TValues extends Record<string, unknown>>({
|
|
|
1464
1478
|
React.useEffect(() => {
|
|
1465
1479
|
const root = rootRef.current
|
|
1466
1480
|
if (!root) return
|
|
1467
|
-
|
|
1481
|
+
const dialog = root.closest<HTMLElement>('[data-dialog-content]')
|
|
1482
|
+
setIsInDialog(Boolean(dialog))
|
|
1483
|
+
setScrolledByPaddedDialog(dialog ? isScrolledByPaddedDialog(root, dialog) : false)
|
|
1468
1484
|
}, [])
|
|
1469
|
-
|
|
1470
|
-
|
|
1471
|
-
|
|
1485
|
+
// Sticky offsets resolve against the scroll container's content box, so when the
|
|
1486
|
+
// padded `DialogContent` (`p-6`, `overflow-y-auto`) is the scroller a `bottom-0`
|
|
1487
|
+
// footer parks 24px above the dialog edge and scrolled fields stay visible in that
|
|
1488
|
+
// padding strip (#7497). Pull the footer down by the dialog padding (`-bottom-6`),
|
|
1489
|
+
// let its own padding paint that strip (`pb-8` = `py-2` + 24px) and cancel the extra
|
|
1490
|
+
// height in normal flow (`-mb-6`) so a short form gets no blank band below the
|
|
1491
|
+
// buttons. A nested, unpadded scroller has no such strip: there `bottom-0` is flush
|
|
1492
|
+
// and the compensation would hang the footer below the scrollport.
|
|
1493
|
+
const dialogFooterClass = !isInDialog
|
|
1494
|
+
? ''
|
|
1495
|
+
: scrolledByPaddedDialog
|
|
1496
|
+
? 'sticky -bottom-6 left-0 right-0 z-20 -mx-6 -mb-6 px-6 pt-2 pb-8 bg-card border-t border-border/70 sm:-mx-6 sm:px-6'
|
|
1497
|
+
: 'sticky bottom-0 left-0 right-0 z-20 -mx-6 px-6 bg-card border-t border-border/70 py-2 sm:-mx-6 sm:px-6'
|
|
1472
1498
|
// No bottom padding on the dialog form. The previous `pb-20` left an 80px gap below
|
|
1473
1499
|
// the sticky footer in every dialog whose content fit the viewport (the form sized to
|
|
1474
1500
|
// content + 80px with the footer as its last child) — visible as empty white space at
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
/** @jest-environment jsdom */
|
|
2
|
+
jest.setTimeout(15000)
|
|
3
|
+
|
|
4
|
+
// Regression guard for #7497: inside a `DialogContent` (`p-6` + `overflow-y-auto`)
|
|
5
|
+
// the sticky CrudForm footer must be pulled down by the dialog padding and paint
|
|
6
|
+
// that strip itself, otherwise scrolled fields stay visible below the buttons.
|
|
7
|
+
// A nested, unpadded scroller (`InlineRuleEditor`) keeps `bottom-0`, because the
|
|
8
|
+
// compensation would hang the footer below that scrollport.
|
|
9
|
+
// Geometry is covered by the browser spec TC-CRM-7497; this pins the class
|
|
10
|
+
// contract so a refactor cannot silently revert either branch.
|
|
11
|
+
jest.mock('next/navigation', () => ({
|
|
12
|
+
useRouter: () => ({ push: () => {} }),
|
|
13
|
+
usePathname: () => '/',
|
|
14
|
+
useSearchParams: () => new URLSearchParams(),
|
|
15
|
+
}))
|
|
16
|
+
jest.mock('remark-gfm', () => ({ __esModule: true, default: {} }))
|
|
17
|
+
jest.mock('../injection/InjectionSpot', () => ({
|
|
18
|
+
__esModule: true,
|
|
19
|
+
InjectionSpot: () => null,
|
|
20
|
+
useInjectionWidgets: () => ({ widgets: [], loading: false, error: null }),
|
|
21
|
+
useInjectionSpotEvents: () => ({ triggerEvent: jest.fn(async () => ({ ok: true, data: {} })) }),
|
|
22
|
+
}))
|
|
23
|
+
jest.mock('../injection/useInjectionDataWidgets', () => ({
|
|
24
|
+
__esModule: true,
|
|
25
|
+
useInjectionDataWidgets: () => ({ widgets: [], isLoading: false, error: null }),
|
|
26
|
+
}))
|
|
27
|
+
|
|
28
|
+
import * as React from 'react'
|
|
29
|
+
import { waitFor } from '@testing-library/react'
|
|
30
|
+
import { renderWithProviders } from '@open-mercato/shared/lib/testing/renderWithProviders'
|
|
31
|
+
import { CrudForm, type CrudField } from '../CrudForm'
|
|
32
|
+
|
|
33
|
+
const fields: CrudField[] = [{ id: 'name', label: 'Name', type: 'text' }]
|
|
34
|
+
|
|
35
|
+
const paddedScrollingDialog: React.CSSProperties = { overflowY: 'auto', padding: '24px' }
|
|
36
|
+
const unpaddedClippingDialog: React.CSSProperties = { overflowY: 'hidden', padding: 0 }
|
|
37
|
+
const unpaddedScroller: React.CSSProperties = { overflowY: 'auto', padding: 0 }
|
|
38
|
+
|
|
39
|
+
function renderForm(wrap: (form: React.ReactElement) => React.ReactElement = (form) => form) {
|
|
40
|
+
const form = React.createElement(CrudForm as never, {
|
|
41
|
+
title: 'Deal',
|
|
42
|
+
entityId: 'customers:deal',
|
|
43
|
+
fields,
|
|
44
|
+
embedded: true,
|
|
45
|
+
submitLabel: 'Save deal',
|
|
46
|
+
onSubmit: () => {},
|
|
47
|
+
})
|
|
48
|
+
return renderWithProviders(wrap(form))
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
function footerOf(container: HTMLElement): HTMLElement {
|
|
52
|
+
const submit = container.querySelector('button[type="submit"]')
|
|
53
|
+
expect(submit).toBeTruthy()
|
|
54
|
+
const footer = submit!.closest('form > div:last-child') as HTMLElement | null
|
|
55
|
+
expect(footer).toBeTruthy()
|
|
56
|
+
return footer!
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
describe('CrudForm dialog footer clipping (#7497)', () => {
|
|
60
|
+
it('pulls the sticky footer flush with the dialog edge and paints the padding strip', async () => {
|
|
61
|
+
const { container } = renderForm((form) => (
|
|
62
|
+
<div data-dialog-content="" style={paddedScrollingDialog}>{form}</div>
|
|
63
|
+
))
|
|
64
|
+
await waitFor(() => expect(container.querySelector('button[type="submit"]')).toBeTruthy())
|
|
65
|
+
const footer = footerOf(container)
|
|
66
|
+
const classes = footer.className.split(/\s+/)
|
|
67
|
+
expect(classes).toEqual(expect.arrayContaining(['sticky', '-bottom-6', '-mb-6', 'pb-8', 'bg-card', '-mx-6', 'px-6']))
|
|
68
|
+
expect(classes).not.toContain('bottom-0')
|
|
69
|
+
})
|
|
70
|
+
|
|
71
|
+
it('keeps the footer at bottom-0 under a nested unpadded scroller', async () => {
|
|
72
|
+
const { container } = renderForm((form) => (
|
|
73
|
+
<div data-dialog-content="" style={unpaddedClippingDialog}>
|
|
74
|
+
<div style={unpaddedScroller}>{form}</div>
|
|
75
|
+
</div>
|
|
76
|
+
))
|
|
77
|
+
await waitFor(() => expect(container.querySelector('button[type="submit"]')).toBeTruthy())
|
|
78
|
+
const classes = footerOf(container).className.split(/\s+/)
|
|
79
|
+
expect(classes).toEqual(expect.arrayContaining(['sticky', 'bottom-0', 'py-2', 'bg-card']))
|
|
80
|
+
for (const compensation of ['-bottom-6', '-mb-6', 'pb-8']) {
|
|
81
|
+
expect(classes).not.toContain(compensation)
|
|
82
|
+
}
|
|
83
|
+
})
|
|
84
|
+
|
|
85
|
+
it('keeps the footer at bottom-0 when the scrolling dialog itself has no padding', async () => {
|
|
86
|
+
const { container } = renderForm((form) => (
|
|
87
|
+
<div data-dialog-content="" style={unpaddedScroller}>{form}</div>
|
|
88
|
+
))
|
|
89
|
+
await waitFor(() => expect(container.querySelector('button[type="submit"]')).toBeTruthy())
|
|
90
|
+
const classes = footerOf(container).className.split(/\s+/)
|
|
91
|
+
expect(classes).toContain('bottom-0')
|
|
92
|
+
expect(classes).not.toContain('-bottom-6')
|
|
93
|
+
})
|
|
94
|
+
|
|
95
|
+
it('leaves the footer unpositioned outside a dialog', async () => {
|
|
96
|
+
const { container } = renderForm()
|
|
97
|
+
await waitFor(() => expect(container.querySelector('button[type="submit"]')).toBeTruthy())
|
|
98
|
+
const footer = footerOf(container)
|
|
99
|
+
expect(footer.className.split(/\s+/)).not.toContain('sticky')
|
|
100
|
+
})
|
|
101
|
+
})
|