@estiva-app/ui 0.98.1 → 0.100.0

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.
Files changed (212) hide show
  1. package/README.md +4 -2
  2. package/dist/AppProvider.d.ts +6 -3
  3. package/dist/AppProvider.d.ts.map +1 -1
  4. package/dist/ArchiveDialog.d.ts +35 -0
  5. package/dist/ArchiveDialog.d.ts.map +1 -0
  6. package/dist/AttachedCard.d.ts +13 -2
  7. package/dist/AttachedCard.d.ts.map +1 -1
  8. package/dist/Card.d.ts +6 -1
  9. package/dist/Card.d.ts.map +1 -1
  10. package/dist/ChipInput.d.ts +3 -1
  11. package/dist/ChipInput.d.ts.map +1 -1
  12. package/dist/CollapsibleSection.d.ts +27 -2
  13. package/dist/CollapsibleSection.d.ts.map +1 -1
  14. package/dist/CommentBox.d.ts +2 -2
  15. package/dist/CommentBox.d.ts.map +1 -1
  16. package/dist/ConfirmDialog.d.ts +15 -2
  17. package/dist/ConfirmDialog.d.ts.map +1 -1
  18. package/dist/ConversationCard.d.ts +12 -1
  19. package/dist/ConversationCard.d.ts.map +1 -1
  20. package/dist/ConversationLayout.d.ts +20 -5
  21. package/dist/ConversationLayout.d.ts.map +1 -1
  22. package/dist/ConversationMenu.d.ts +5 -1
  23. package/dist/ConversationMenu.d.ts.map +1 -1
  24. package/dist/ConversationPlace.d.ts +17 -0
  25. package/dist/ConversationPlace.d.ts.map +1 -0
  26. package/dist/DocumentEditor.d.ts +38 -0
  27. package/dist/DocumentEditor.d.ts.map +1 -1
  28. package/dist/DocumentField.d.ts +50 -0
  29. package/dist/DocumentField.d.ts.map +1 -0
  30. package/dist/EditableText.d.ts +38 -4
  31. package/dist/EditableText.d.ts.map +1 -1
  32. package/dist/EmptyState.d.ts +10 -5
  33. package/dist/EmptyState.d.ts.map +1 -1
  34. package/dist/FormDialog.d.ts +38 -0
  35. package/dist/FormDialog.d.ts.map +1 -0
  36. package/dist/InlineText.d.ts.map +1 -1
  37. package/dist/Menu.d.ts +11 -3
  38. package/dist/Menu.d.ts.map +1 -1
  39. package/dist/MoveDialog.d.ts +64 -0
  40. package/dist/MoveDialog.d.ts.map +1 -0
  41. package/dist/NavItem.d.ts +9 -2
  42. package/dist/NavItem.d.ts.map +1 -1
  43. package/dist/NavTree.d.ts +16 -3
  44. package/dist/NavTree.d.ts.map +1 -1
  45. package/dist/PinnedComment.d.ts +3 -1
  46. package/dist/PinnedComment.d.ts.map +1 -1
  47. package/dist/ReactionHorizon.d.ts +3 -1
  48. package/dist/ReactionHorizon.d.ts.map +1 -1
  49. package/dist/RepliesRow.d.ts +5 -3
  50. package/dist/RepliesRow.d.ts.map +1 -1
  51. package/dist/ResolveDialog.d.ts +3 -1
  52. package/dist/ResolveDialog.d.ts.map +1 -1
  53. package/dist/SelectionToolbar.d.ts +2 -2
  54. package/dist/Thread.d.ts +6 -3
  55. package/dist/Thread.d.ts.map +1 -1
  56. package/dist/commentBoxFrame.d.ts.map +1 -1
  57. package/dist/conversation.examples.d.ts +4 -1
  58. package/dist/conversation.examples.d.ts.map +1 -1
  59. package/dist/conversationScroll.d.ts +80 -0
  60. package/dist/conversationScroll.d.ts.map +1 -0
  61. package/dist/editor.d.ts +1 -0
  62. package/dist/editor.d.ts.map +1 -1
  63. package/dist/editor.js +228 -69
  64. package/dist/editor.js.map +4 -4
  65. package/dist/eslint/index.js +2 -2
  66. package/dist/eslint/index.js.map +2 -2
  67. package/dist/eslint/no-field-outside-a-form.d.ts +2 -2
  68. package/dist/eslint/no-field-outside-a-form.d.ts.map +1 -1
  69. package/dist/eslint/no-native-title.d.ts +1 -1
  70. package/dist/eslint/no-native-title.d.ts.map +1 -1
  71. package/dist/formBusy.d.ts +5 -2
  72. package/dist/formBusy.d.ts.map +1 -1
  73. package/dist/index.d.ts +14 -6
  74. package/dist/index.d.ts.map +1 -1
  75. package/dist/index.js +2242 -1471
  76. package/dist/index.js.map +4 -4
  77. package/dist/looks.d.ts +8 -0
  78. package/dist/looks.d.ts.map +1 -1
  79. package/dist/seenOnScreen.d.ts +27 -0
  80. package/dist/seenOnScreen.d.ts.map +1 -0
  81. package/dist/showInConversation.d.ts +31 -0
  82. package/dist/showInConversation.d.ts.map +1 -0
  83. package/dist/threadCard.d.ts +13 -0
  84. package/dist/threadCard.d.ts.map +1 -1
  85. package/package.json +1 -1
  86. package/registry.json +953 -126
  87. package/src/AppProvider.mdx +4 -0
  88. package/src/AppProvider.test.tsx +34 -2
  89. package/src/AppProvider.tsx +17 -6
  90. package/src/ArchiveDialog.mdx +70 -0
  91. package/src/ArchiveDialog.stories.tsx +64 -0
  92. package/src/ArchiveDialog.test.tsx +90 -0
  93. package/src/ArchiveDialog.tsx +70 -0
  94. package/src/AttachedCard.mdx +6 -0
  95. package/src/AttachedCard.stories.tsx +9 -1
  96. package/src/AttachedCard.test.tsx +111 -2
  97. package/src/AttachedCard.tsx +77 -7
  98. package/src/Card.mdx +20 -1
  99. package/src/Card.stories.tsx +20 -0
  100. package/src/Card.test.tsx +87 -1
  101. package/src/Card.tsx +51 -3
  102. package/src/ChipInput.mdx +7 -1
  103. package/src/ChipInput.stories.tsx +9 -0
  104. package/src/ChipInput.test.tsx +42 -0
  105. package/src/ChipInput.tsx +7 -3
  106. package/src/CollapsibleSection.mdx +20 -1
  107. package/src/CollapsibleSection.stories.tsx +19 -1
  108. package/src/CollapsibleSection.test.tsx +85 -2
  109. package/src/CollapsibleSection.tsx +54 -15
  110. package/src/CommentBox.mdx +2 -1
  111. package/src/CommentBox.test.tsx +81 -1
  112. package/src/CommentBox.tsx +32 -11
  113. package/src/ConfirmDialog.mdx +25 -3
  114. package/src/ConfirmDialog.stories.tsx +27 -0
  115. package/src/ConfirmDialog.test.tsx +87 -1
  116. package/src/ConfirmDialog.tsx +39 -8
  117. package/src/ConversationCard.mdx +7 -0
  118. package/src/ConversationCard.states.test.tsx +67 -0
  119. package/src/ConversationCard.stories.tsx +27 -1
  120. package/src/ConversationCard.test.tsx +76 -0
  121. package/src/ConversationCard.tsx +65 -53
  122. package/src/ConversationLayout.mdx +34 -4
  123. package/src/ConversationLayout.scroll.test.tsx +411 -0
  124. package/src/ConversationLayout.stories.tsx +107 -1
  125. package/src/ConversationLayout.test.tsx +133 -0
  126. package/src/ConversationLayout.tsx +141 -16
  127. package/src/ConversationMenu.mdx +3 -0
  128. package/src/ConversationMenu.stories.tsx +12 -0
  129. package/src/ConversationMenu.test.tsx +17 -0
  130. package/src/ConversationMenu.tsx +7 -3
  131. package/src/ConversationPlace.mdx +53 -0
  132. package/src/ConversationPlace.stories.tsx +48 -0
  133. package/src/ConversationPlace.test.tsx +51 -0
  134. package/src/ConversationPlace.tsx +30 -0
  135. package/src/DocumentEditor.mdx +2 -1
  136. package/src/DocumentEditor.tsx +118 -64
  137. package/src/DocumentField.mdx +83 -0
  138. package/src/DocumentField.stories.tsx +110 -0
  139. package/src/DocumentField.test.tsx +281 -0
  140. package/src/DocumentField.tsx +199 -0
  141. package/src/EditableText.buttons.test.tsx +318 -0
  142. package/src/EditableText.mdx +50 -2
  143. package/src/EditableText.stories.tsx +96 -2
  144. package/src/EditableText.tsx +189 -5
  145. package/src/EmptyState.mdx +33 -8
  146. package/src/EmptyState.stories.tsx +26 -1
  147. package/src/EmptyState.test.tsx +63 -2
  148. package/src/EmptyState.tsx +28 -6
  149. package/src/Form.mdx +3 -1
  150. package/src/FormDialog.mdx +78 -0
  151. package/src/FormDialog.stories.tsx +90 -0
  152. package/src/FormDialog.test.tsx +183 -0
  153. package/src/FormDialog.tsx +93 -0
  154. package/src/InlineText.mdx +1 -0
  155. package/src/InlineText.tsx +2 -1
  156. package/src/Menu.test.tsx +80 -0
  157. package/src/Menu.tsx +35 -14
  158. package/src/MenuItem.mdx +12 -0
  159. package/src/MenuItem.stories.tsx +39 -1
  160. package/src/MoveDialog.mdx +85 -0
  161. package/src/MoveDialog.stories.tsx +134 -0
  162. package/src/MoveDialog.test.tsx +239 -0
  163. package/src/MoveDialog.tsx +186 -0
  164. package/src/NavItem.mdx +15 -0
  165. package/src/NavItem.stories.tsx +15 -0
  166. package/src/NavItem.test.tsx +64 -1
  167. package/src/NavItem.tsx +10 -2
  168. package/src/NavTree.mdx +26 -4
  169. package/src/NavTree.stories.tsx +59 -0
  170. package/src/NavTree.test.tsx +232 -2
  171. package/src/NavTree.tsx +93 -43
  172. package/src/PinnedComment.mdx +6 -1
  173. package/src/PinnedComment.stories.tsx +11 -1
  174. package/src/PinnedComment.tsx +15 -2
  175. package/src/ReactionHorizon.mdx +2 -0
  176. package/src/ReactionHorizon.stories.tsx +3 -0
  177. package/src/ReactionHorizon.test.tsx +32 -0
  178. package/src/ReactionHorizon.tsx +28 -11
  179. package/src/RepliesRow.mdx +6 -3
  180. package/src/RepliesRow.stories.tsx +3 -0
  181. package/src/RepliesRow.test.tsx +24 -0
  182. package/src/RepliesRow.tsx +12 -6
  183. package/src/ReplyCard.mdx +8 -0
  184. package/src/ReplyCard.stories.tsx +45 -1
  185. package/src/ResolveDialog.mdx +2 -0
  186. package/src/ResolveDialog.test.tsx +21 -0
  187. package/src/ResolveDialog.tsx +11 -39
  188. package/src/SelectionToolbar.tsx +2 -2
  189. package/src/Textarea.mdx +1 -0
  190. package/src/Thread.mdx +20 -1
  191. package/src/Thread.stories.tsx +94 -3
  192. package/src/Thread.test.tsx +11 -0
  193. package/src/Thread.tsx +56 -12
  194. package/src/commentBoxFrame.tsx +2 -2
  195. package/src/conversation.examples.tsx +10 -2
  196. package/src/conversationScroll.ts +155 -0
  197. package/src/editor.ts +1 -0
  198. package/src/editorSelection.test.tsx +53 -0
  199. package/src/eslint/no-field-outside-a-form.test.ts +4 -0
  200. package/src/eslint/no-field-outside-a-form.ts +2 -2
  201. package/src/eslint/no-native-title.ts +1 -1
  202. package/src/formBusy.ts +5 -2
  203. package/src/index.ts +16 -6
  204. package/src/looks.ts +10 -0
  205. package/src/registry/registry.test.ts +12 -6
  206. package/src/seenOnScreen.test.tsx +241 -0
  207. package/src/seenOnScreen.ts +146 -0
  208. package/src/showInConversation.test.tsx +168 -0
  209. package/src/showInConversation.ts +93 -0
  210. package/src/threadCard.ts +16 -0
  211. package/stories/Choosing.mdx +8 -3
  212. package/tailwind-preset.js +7 -0
@@ -0,0 +1,90 @@
1
+ import type { Meta, StoryObj } from '@storybook/react-vite'
2
+ import { useState } from 'react'
3
+ import { userEvent, within } from 'storybook/test'
4
+ import { EmptyState } from './EmptyState'
5
+ import { Field } from './Field'
6
+ import { FormDialog } from './FormDialog'
7
+ import { TextInput } from './TextInput'
8
+
9
+ /** A dialog that sends a form: the words, the fields, Cancel and the button that sends it. */
10
+ const meta = {
11
+ title: 'Menus & windows/FormDialog',
12
+ component: FormDialog,
13
+ parameters: {
14
+ layout: 'fullscreen',
15
+ // Portals a fixed overlay to document.body: an iframe on the Docs page, so it stays in its frame.
16
+ docs: { story: { inline: false, height: '400px' } },
17
+ },
18
+ argTypes: { children: { control: false }, onSubmit: { control: false }, onClose: { control: false } },
19
+ args: {
20
+ title: 'New folder',
21
+ submitLabel: 'Create',
22
+ busyLabel: 'Creating…',
23
+ onSubmit: () => {},
24
+ onClose: () => {},
25
+ children: null,
26
+ },
27
+ } satisfies Meta<typeof FormDialog>
28
+
29
+ export default meta
30
+ type Story = StoryObj<typeof meta>
31
+
32
+ /** One field and the sentence before it. Create waits for a name; Enter in the field sends. */
33
+ export const NewFolder: Story = {
34
+ name: 'New folder',
35
+ parameters: { controls: { disable: true } },
36
+ render: (args) => {
37
+ const [name, setName] = useState('')
38
+ return (
39
+ <FormDialog {...args} ready={!!name.trim()}>
40
+ <p className="text-body-2 text-text-secondary">A place for files and conversations. Everyone you add to it can read what is in it.</p>
41
+ <Field label="Folder name">
42
+ <TextInput value={name} onChange={(event) => setName(event.target.value)} placeholder="What is it for?" autoFocus />
43
+ </Field>
44
+ </FormDialog>
45
+ )
46
+ },
47
+ }
48
+
49
+ /** Sending: the button says so, and the field and both buttons wait for the answer. */
50
+ export const Sending: Story = {
51
+ parameters: { controls: { disable: true } },
52
+ args: { onSubmit: () => new Promise<void>(() => {}) },
53
+ render: NewFolder.render,
54
+ play: async ({ canvasElement }) => {
55
+ const page = within(canvasElement.ownerDocument.body)
56
+ await userEvent.type(page.getByRole('textbox', { name: 'Folder name' }), 'Steer')
57
+ await userEvent.click(page.getByRole('button', { name: 'Create' }))
58
+ },
59
+ }
60
+
61
+ /** Refused: the answer was `false`, so it stays open with what was typed, and the caller says why. */
62
+ export const Refused: Story = {
63
+ parameters: { controls: { disable: true } },
64
+ args: { onSubmit: () => false },
65
+ render: NewFolder.render,
66
+ play: Sending.play,
67
+ }
68
+
69
+ /** Nothing to choose from: a section's empty line where the fields would be, and the button greyed. */
70
+ export const NothingToChoose: Story = {
71
+ name: 'Nothing to choose',
72
+ args: { title: 'Move', submitLabel: 'Move', busyLabel: 'Moving…', ready: false, children: <EmptyState scope="section" message="There is no other folder it can be moved to." /> },
73
+ }
74
+
75
+ /** A Resolve: the kit's `resolve` look on the sending button, as `ResolveDialog` draws it. */
76
+ export const ResolveLook: Story = {
77
+ name: 'Resolve look',
78
+ parameters: { controls: { disable: true } },
79
+ args: { title: 'Resolve', submitLabel: 'Resolve', busyLabel: undefined, submitVariant: 'resolve' },
80
+ render: (args) => {
81
+ const [note, setNote] = useState('')
82
+ return (
83
+ <FormDialog {...args}>
84
+ <Field label="Resolution message (optional)">
85
+ <TextInput value={note} onChange={(event) => setNote(event.target.value)} />
86
+ </Field>
87
+ </FormDialog>
88
+ )
89
+ },
90
+ }
@@ -0,0 +1,183 @@
1
+ // @vitest-environment jsdom
2
+ /**
3
+ * A dialog that sends a form: what Peek's Archive, New folder, Move and Start
4
+ * a topic each wired by hand (C10, 2 November), pinned once.
5
+ */
6
+ import { afterEach, describe, expect, it, vi } from 'vitest'
7
+ import { act, cleanup, render, screen, waitFor } from '@testing-library/react'
8
+ import userEvent from '@testing-library/user-event'
9
+ import { useState } from 'react'
10
+ import { FormDialog, type FormDialogProps } from './FormDialog'
11
+ import { Field } from './Field'
12
+ import { TextInput } from './TextInput'
13
+
14
+ afterEach(cleanup)
15
+
16
+ function Fixture(props: Partial<FormDialogProps>) {
17
+ const [name, setName] = useState('')
18
+ return (
19
+ <FormDialog title="New folder" submitLabel="Create" busyLabel="Creating…" ready={!!name.trim()} onSubmit={() => {}} onClose={() => {}} {...props}>
20
+ <p>A place for files and conversations.</p>
21
+ <Field label="Folder name">
22
+ <TextInput value={name} onChange={(event) => setName(event.target.value)} />
23
+ </Field>
24
+ </FormDialog>
25
+ )
26
+ }
27
+
28
+ const pending = () => {
29
+ let release: (value: boolean | void) => void = () => {}
30
+ const promise = new Promise<boolean | void>((resolve) => {
31
+ release = resolve
32
+ })
33
+ return { promise, release: (value?: boolean) => release(value) }
34
+ }
35
+
36
+ describe('FormDialog', () => {
37
+ it('is a dialog named by its title, holding a form, with Cancel and the button that sends it', () => {
38
+ render(<Fixture />)
39
+ const dialog = screen.getByRole('dialog', { name: 'New folder' })
40
+ expect(dialog.querySelector('form')).not.toBeNull()
41
+ expect(screen.getByRole('button', { name: 'Cancel' })).toBeTruthy()
42
+ const send = screen.getByRole('button', { name: 'Create' }) as HTMLButtonElement
43
+ expect(send.type).toBe('submit')
44
+ expect(send.getAttribute('form')).toBe(dialog.querySelector('form')!.id)
45
+ })
46
+
47
+ it('sends from its button and from Enter in a field, once there is enough to send', async () => {
48
+ const user = userEvent.setup()
49
+ const onSubmit = vi.fn(() => false)
50
+ render(<Fixture onSubmit={onSubmit} />)
51
+ const send = screen.getByRole('button', { name: 'Create' }) as HTMLButtonElement
52
+ expect(send.disabled).toBe(true)
53
+ await user.keyboard('{Enter}')
54
+ expect(onSubmit).not.toHaveBeenCalled()
55
+ await user.type(screen.getByRole('textbox', { name: 'Folder name' }), 'Steer{Enter}')
56
+ expect(onSubmit).toHaveBeenCalledTimes(1)
57
+ expect(send.disabled).toBe(false)
58
+ await user.click(send)
59
+ expect(onSubmit).toHaveBeenCalledTimes(2)
60
+ })
61
+
62
+ it('sends nothing while not ready, not even on Ctrl+Enter', async () => {
63
+ const user = userEvent.setup()
64
+ const onSubmit = vi.fn()
65
+ render(<Fixture ready={false} onSubmit={onSubmit} />)
66
+ await user.type(screen.getByRole('textbox', { name: 'Folder name' }), 'Steer{Control>}{Enter}{/Control}')
67
+ expect(onSubmit).not.toHaveBeenCalled()
68
+ })
69
+
70
+ it('while it sends: the button says so, both buttons wait, and the fields are off', async () => {
71
+ const user = userEvent.setup()
72
+ const sending = pending()
73
+ render(<Fixture onSubmit={() => sending.promise} />)
74
+ await user.type(screen.getByRole('textbox', { name: 'Folder name' }), 'Steer')
75
+ await user.click(screen.getByRole('button', { name: 'Create' }))
76
+ const send = screen.getByRole('button', { name: 'Creating…' }) as HTMLButtonElement
77
+ expect(send.disabled).toBe(true)
78
+ // Cancel too: nothing can stop a send under way, so a Cancel then would say what is not so.
79
+ expect((screen.getByRole('button', { name: 'Cancel' }) as HTMLButtonElement).disabled).toBe(true)
80
+ expect((screen.getByRole('textbox', { name: 'Folder name' }) as HTMLInputElement).disabled).toBe(true)
81
+ sending.release(false)
82
+ await waitFor(() => expect(screen.getByRole('button', { name: 'Create' })).toBeTruthy())
83
+ expect((screen.getByRole('button', { name: 'Cancel' }) as HTMLButtonElement).disabled).toBe(false)
84
+ })
85
+
86
+ it('keeps its words on the button while it sends when it has no busy words', async () => {
87
+ const user = userEvent.setup()
88
+ render(<Fixture busyLabel={undefined} submitLabel="Archive topic" ready onSubmit={() => pending().promise} />)
89
+ await user.click(screen.getByRole('button', { name: 'Archive topic' }))
90
+ expect((screen.getByRole('button', { name: 'Archive topic' }) as HTMLButtonElement).disabled).toBe(true)
91
+ })
92
+
93
+ it('closes when the send went through, and stays open when it was refused', async () => {
94
+ const user = userEvent.setup()
95
+ const onClose = vi.fn()
96
+ const { unmount } = render(<Fixture ready onSubmit={async () => false} onClose={onClose} />)
97
+ await user.click(screen.getByRole('button', { name: 'Create' }))
98
+ await waitFor(() => expect((screen.getByRole('button', { name: 'Create' }) as HTMLButtonElement).disabled).toBe(false))
99
+ expect(onClose).not.toHaveBeenCalled()
100
+ unmount()
101
+ for (const answer of [true, undefined]) {
102
+ const closed = vi.fn()
103
+ const { unmount: done } = render(<Fixture ready onSubmit={async () => answer} onClose={closed} />)
104
+ await user.click(screen.getByRole('button', { name: 'Create' }))
105
+ await waitFor(() => expect(closed).toHaveBeenCalledOnce())
106
+ done()
107
+ }
108
+ })
109
+
110
+ it('a send that throws is a refusal: it stays open, and the buttons come back', async () => {
111
+ const user = userEvent.setup()
112
+ const onClose = vi.fn()
113
+ render(
114
+ <Fixture
115
+ ready
116
+ onSubmit={async () => {
117
+ throw new Error('down')
118
+ }}
119
+ onClose={onClose}
120
+ />,
121
+ )
122
+ await user.click(screen.getByRole('button', { name: 'Create' }))
123
+ await waitFor(() => expect((screen.getByRole('button', { name: 'Create' }) as HTMLButtonElement).disabled).toBe(false))
124
+ expect(onClose).not.toHaveBeenCalled()
125
+ })
126
+
127
+ it('sends once, however often it is asked while it sends', async () => {
128
+ const user = userEvent.setup()
129
+ const sending = pending()
130
+ const onSubmit = vi.fn(() => sending.promise)
131
+ render(<Fixture onSubmit={onSubmit} />)
132
+ const field = screen.getByRole('textbox', { name: 'Folder name' })
133
+ await user.type(field, 'Steer')
134
+ await user.keyboard('{Control>}{Enter}{Enter}{/Control}')
135
+ expect(onSubmit).toHaveBeenCalledTimes(1)
136
+ sending.release(true)
137
+ })
138
+
139
+ it('closed with Escape while it sends, it is closed once, not again when the send goes through', async () => {
140
+ const user = userEvent.setup()
141
+ const sending = pending()
142
+ const onClose = vi.fn()
143
+ function Page() {
144
+ const [open, setOpen] = useState(true)
145
+ return open ? (
146
+ <Fixture
147
+ ready
148
+ onSubmit={() => sending.promise}
149
+ onClose={() => {
150
+ onClose()
151
+ setOpen(false)
152
+ }}
153
+ />
154
+ ) : null
155
+ }
156
+ render(<Page />)
157
+ await user.click(screen.getByRole('button', { name: 'Create' }))
158
+ await user.keyboard('{Escape}')
159
+ expect(onClose).toHaveBeenCalledOnce()
160
+ await act(async () => sending.release(true))
161
+ expect(onClose).toHaveBeenCalledOnce()
162
+ })
163
+
164
+ it('Cancel closes without sending', async () => {
165
+ const user = userEvent.setup()
166
+ const onSubmit = vi.fn()
167
+ const onClose = vi.fn()
168
+ render(<Fixture ready onSubmit={onSubmit} onClose={onClose} />)
169
+ await user.click(screen.getByRole('button', { name: 'Cancel' }))
170
+ expect(onClose).toHaveBeenCalledOnce()
171
+ expect(onSubmit).not.toHaveBeenCalled()
172
+ })
173
+
174
+ it('the send button is primary, or the kit’s Resolve look', () => {
175
+ const { unmount } = render(<Fixture ready />)
176
+ expect(screen.getByRole('button', { name: 'Create' }).className).toContain('bg-accent-primary')
177
+ unmount()
178
+ render(<Fixture ready submitLabel="Resolve" submitVariant="resolve" />)
179
+ const resolve = screen.getByRole('button', { name: 'Resolve' })
180
+ expect(resolve.className).not.toContain('bg-accent-primary')
181
+ expect(resolve.className).toContain('hover:bg-success-muted')
182
+ })
183
+ })
@@ -0,0 +1,93 @@
1
+ import { useId, useRef, useState, type ReactNode } from 'react'
2
+ import { Button } from './Button'
3
+ import { DialogShell } from './DialogShell'
4
+ import { Form } from './Form'
5
+
6
+ /**
7
+ * A dialog that sends a form: `DialogShell` holding a `Form`, with Cancel and
8
+ * the button that sends it in the footer — what Peek's Archive, New folder,
9
+ * Move and Start a topic each wired by hand, and `ResolveDialog` too (C10,
10
+ * 2 November). The look is theirs, unchanged.
11
+ *
12
+ * It owns the send: the button says its busy words while it waits, the fields
13
+ * and both buttons are off until the answer comes, and a send that went
14
+ * through closes it. An answer of `false` keeps it open, because the caller
15
+ * has said why; so does a throw.
16
+ *
17
+ * **Cancel waits too** (decided once for all, 2 November; only Peek's Archive
18
+ * did it before): nothing can stop a send already under way, so a Cancel
19
+ * pressed then would close over a write still running, and its answer, a
20
+ * refusal included, would have nowhere to land. `ConfirmDialog` waits the same
21
+ * way. Escape and the ✕ still close it, as they do there.
22
+ */
23
+ export interface FormDialogProps {
24
+ /** The dialog's heading. */
25
+ title: string
26
+ /** The words on the button that sends the form: "Move", "Create". */
27
+ submitLabel: string
28
+ /** Its words while the form sends — "Moving…". Absent, they stay as they are. */
29
+ busyLabel?: string
30
+ /** How the sending button looks: `primary`, or `resolve` for a Resolve. */
31
+ submitVariant?: 'primary' | 'resolve'
32
+ /** Whether there is enough to send. While it is not, the button is greyed and Enter sends nothing. */
33
+ ready?: boolean
34
+ /** Sends the form. Answer `false` to keep the dialog open (you have said why); anything else closes it. */
35
+ onSubmit: () => Promise<boolean | void> | boolean | void
36
+ /** Cancel, Escape, the ✕, a press outside, and a send that went through: once, when it was closed while it sent. */
37
+ onClose: () => void
38
+ /** What the form holds: the words before the fields, then the fields. The form puts 24px between them. */
39
+ children: ReactNode
40
+ }
41
+
42
+ export function FormDialog({ title, submitLabel, busyLabel, submitVariant = 'primary', ready = true, onSubmit, onClose, children }: FormDialogProps) {
43
+ const [busy, setBusy] = useState(false)
44
+ // Known at once rather than at the next render: two Ctrl+Enters before it re-renders send once.
45
+ const sending = useRef(false)
46
+ // Closed while it sent (Escape, the ✕): the send that then goes through does not close it a second time.
47
+ const closed = useRef(false)
48
+ const formId = useId()
49
+
50
+ const close = () => {
51
+ closed.current = true
52
+ onClose()
53
+ }
54
+
55
+ const send = async () => {
56
+ if (!ready || sending.current) return
57
+ sending.current = true
58
+ closed.current = false
59
+ setBusy(true)
60
+ let answer: boolean | void = false
61
+ try {
62
+ answer = await onSubmit()
63
+ } catch {
64
+ /* a refusal: the caller has said why, and the dialog stays */
65
+ answer = false
66
+ } finally {
67
+ sending.current = false
68
+ setBusy(false)
69
+ }
70
+ if (answer !== false && !closed.current) close()
71
+ }
72
+
73
+ return (
74
+ <DialogShell
75
+ title={title}
76
+ onClose={close}
77
+ footer={
78
+ <>
79
+ <Button variant="muted" onClick={close} disabled={busy}>
80
+ Cancel
81
+ </Button>
82
+ <Button variant={submitVariant} type="submit" form={formId} disabled={!ready || busy}>
83
+ {busy && busyLabel ? busyLabel : submitLabel}
84
+ </Button>
85
+ </>
86
+ }
87
+ >
88
+ <Form id={formId} busy={busy} onSubmit={send}>
89
+ {children}
90
+ </Form>
91
+ </DialogShell>
92
+ )
93
+ }
@@ -53,6 +53,7 @@ It does these by itself. Write none of them around it.
53
53
  | An unchanged or (for a title) empty value is not a write | a compare before saving |
54
54
  | Your text stays after a refused save, and a change from elsewhere waits | a draft kept beside it |
55
55
  | The placeholder while it is empty | an empty check |
56
+ | Selected words painted in the selected colour, as in every editor | a `::selection` rule |
56
57
 
57
58
  ## Keys
58
59
 
@@ -3,6 +3,7 @@ import { Extension, Node } from '@tiptap/core'
3
3
  import { history, redo, undo } from '@tiptap/pm/history'
4
4
  import { EditorContent, useEditor } from '@tiptap/react'
5
5
  import { cn } from './cn'
6
+ import { EDITOR_SELECTION_CLASSES } from './looks'
6
7
 
7
8
  /**
8
9
  * A line of plain text on a page that you edit where it stands, as in a
@@ -132,7 +133,7 @@ export function InlineText({ value, placeholder, label, onCommit, onText, onEnte
132
133
  'aria-multiline': 'false',
133
134
  'aria-placeholder': placeholder,
134
135
  ...(readOnly ? { 'aria-readonly': 'true' } : {}),
135
- class: 'outline-none',
136
+ class: cn('outline-none', EDITOR_SELECTION_CLASSES),
136
137
  },
137
138
  handleKeyDown: (view, event) => {
138
139
  if (event.key === 'Enter') {
package/src/Menu.test.tsx CHANGED
@@ -364,3 +364,83 @@ describe('Menu, padding', () => {
364
364
  expect(classes).not.toContain('p-2')
365
365
  })
366
366
  })
367
+
368
+ describe('MenuItem, shown but shut, saying why (disabledReason; Ship, 2 November)', () => {
369
+ function Shut({ onClick }: { onClick: () => void }) {
370
+ return (
371
+ <Menu trigger={<Button variant="outlined">Trigger</Button>}>
372
+ <MenuItem label="Rename" onClick={() => {}} />
373
+ <MenuItem label="Archive" disabledReason="Archived with its project: unarchive the project." onClick={onClick} />
374
+ </Menu>
375
+ )
376
+ }
377
+
378
+ it('is shown, shut: a press runs nothing and the menu stays open', async () => {
379
+ const user = userEvent.setup()
380
+ const onClick = vi.fn()
381
+ render(<Shut onClick={onClick} />)
382
+ await user.click(screen.getByRole('button', { name: 'Trigger' }))
383
+ const row = await screen.findByRole('menuitem', { name: 'Archive' })
384
+ expect(row.getAttribute('aria-disabled')).toBe('true')
385
+ await user.click(row)
386
+ expect(onClick).not.toHaveBeenCalled()
387
+ expect(screen.getByRole('menu')).toBeTruthy()
388
+ })
389
+
390
+ it('says why under the pointer', async () => {
391
+ const user = userEvent.setup()
392
+ render(<Shut onClick={() => {}} />)
393
+ await user.click(screen.getByRole('button', { name: 'Trigger' }))
394
+ await user.hover(await screen.findByRole('menuitem', { name: 'Archive' }))
395
+ expect((await screen.findByRole('tooltip')).textContent).toBe('Archived with its project: unarchive the project.')
396
+ })
397
+
398
+ it('stays where the arrow keys go, so the keyboard reaches the reason too', async () => {
399
+ const user = userEvent.setup()
400
+ render(<Shut onClick={() => {}} />)
401
+ screen.getByRole('button', { name: 'Trigger' }).focus()
402
+ await user.keyboard('{Enter}')
403
+ await screen.findByRole('menu')
404
+ await user.keyboard('{ArrowDown}')
405
+ await waitFor(() => expect(document.activeElement?.textContent).toBe('Archive'))
406
+ expect((await screen.findByRole('tooltip')).textContent).toBe('Archived with its project: unarchive the project.')
407
+ })
408
+
409
+ it('never takes the fill, under the pointer or the arrow keys (Katerina, 2 November); an open row keeps it', async () => {
410
+ const user = userEvent.setup()
411
+ render(<Shut onClick={() => {}} />)
412
+ await user.click(screen.getByRole('button', { name: 'Trigger' }))
413
+ const fills = (row: HTMLElement) => row.className.split(/\s+/).filter((c) => c.endsWith('bg-bg-hover'))
414
+ const shut = await screen.findByRole('menuitem', { name: 'Archive' })
415
+ expect(fills(shut)).toEqual([])
416
+ expect(fills(screen.getByRole('menuitem', { name: 'Rename' })).length).toBeGreaterThan(0)
417
+ await user.hover(shut)
418
+ expect(fills(shut)).toEqual([])
419
+ })
420
+
421
+ it('on a bare MenuPanel, no fill either', () => {
422
+ render(
423
+ <MenuPanel>
424
+ <MenuItem label="Archive" disabledReason="Archived with its project." onClick={() => {}} />
425
+ </MenuPanel>,
426
+ )
427
+ expect(screen.getByRole('button', { name: 'Archive' }).className.split(/\s+/).filter((c) => c.endsWith('bg-bg-hover'))).toEqual([])
428
+ })
429
+
430
+ it('on a bare MenuPanel too: shut, and a press runs nothing', async () => {
431
+ const user = userEvent.setup()
432
+ const onClick = vi.fn()
433
+ render(
434
+ <MenuPanel>
435
+ <MenuItem label="Archive" disabledReason="Archived with its project." onClick={onClick} />
436
+ </MenuPanel>,
437
+ )
438
+ const row = screen.getByRole('button', { name: 'Archive' })
439
+ expect(row.getAttribute('aria-disabled')).toBe('true')
440
+ await user.hover(row)
441
+ expect((await screen.findByRole('tooltip')).textContent).toBe('Archived with its project.')
442
+ await user.click(row)
443
+ await user.keyboard('{Enter}')
444
+ expect(onClick).not.toHaveBeenCalled()
445
+ })
446
+ })
package/src/Menu.tsx CHANGED
@@ -5,6 +5,7 @@ import { cn } from './cn'
5
5
  import { Divider, DividerInPanel } from './Divider'
6
6
  import { triggerDisabled } from './triggerDisabled'
7
7
  import { ScrollArea } from './ScrollArea'
8
+ import { TooltipTrigger } from './Tooltip'
8
9
  import { Kbd } from './Kbd'
9
10
  import { SectionLabel } from './SectionLabel'
10
11
  import { FLOATING_SURFACE_CLASSES } from './looks'
@@ -384,6 +385,11 @@ export interface MenuItemProps extends Omit<ComponentPropsWithRef<'button'>, 'ch
384
385
  destructive?: boolean
385
386
  /** The row the menu currently points at (a submenu's chosen value). */
386
387
  selected?: boolean
388
+ /**
389
+ * Why it cannot be chosen right now: the row is shown, shut, in the disabled colour, with no fill, and says why under
390
+ * the pointer and when the arrow keys reach it, as `Button`'s does. A press runs nothing and the menu stays open.
391
+ */
392
+ disabledReason?: string
387
393
  }
388
394
 
389
395
  /**
@@ -398,7 +404,7 @@ export interface MenuItemProps extends Omit<ComponentPropsWithRef<'button'>, 'ch
398
404
  * `Select` puts it on Base UI's `Select.Item`, whose parts (`ItemText`,
399
405
  * `ItemIndicator`) have to stay the element's own. One row, two parts. Not
400
406
  * exported from the package's index. */
401
- export function menuItemClassName({ size, selected, className }: { size: 'default' | 'tall'; selected?: boolean; className?: string }) {
407
+ export function menuItemClassName({ size, selected, shut = false, className }: { size: 'default' | 'tall'; selected?: boolean; shut?: boolean; className?: string }) {
402
408
  return cn(
403
409
  // shrink-0: a menu is a flex column that scrolls at its max height,
404
410
  // and a flex child shrinks before its container does — so every row
@@ -414,7 +420,9 @@ export function menuItemClassName({ size, selected, className }: { size: 'defaul
414
420
  // hint flickering in and out. Both are instant now: they still change
415
421
  // on exactly the same :hover, so they cannot come apart, and a row
416
422
  // lights and unlights crisply as the pointer crosses it.
417
- 'group flex w-full shrink-0 cursor-pointer items-center rounded-lg text-left outline-none hover:bg-bg-hover data-[highlighted]:bg-bg-hover',
423
+ 'group flex w-full shrink-0 cursor-pointer items-center rounded-lg text-left outline-none',
424
+ // The fill under the pointer and the arrow keys: never on a shut row (Katerina, 2 November), whose reason shows instead.
425
+ !shut && 'hover:bg-bg-hover data-[highlighted]:bg-bg-hover',
418
426
  // Both sizes are as tall as their content and never shorter than a
419
427
  // floor: 36px for a default row (Katerina, 2026-09-11), 40px for a
420
428
  // tall one (Katerina, 2026-09-01). A single-line action row sits at
@@ -424,6 +432,9 @@ export function menuItemClassName({ size, selected, className }: { size: 'defaul
424
432
  // this 36px and was the only menu in either app out of step.
425
433
  size === 'tall' ? 'min-h-10 gap-3 px-3 py-1.5' : 'min-h-9 gap-2 px-2 py-1.5',
426
434
  selected && 'bg-bg-hover',
435
+ // Shut, with its reason: the arrow, not the hand, and its icon in the disabled colour as its words are, as a
436
+ // disabled IconButton draws its own. No fill under the pointer or the arrow keys: its reason is what shows there.
437
+ shut && 'cursor-default [&_svg]:text-text-disabled',
427
438
  className,
428
439
  )
429
440
  }
@@ -431,7 +442,9 @@ export function menuItemClassName({ size, selected, className }: { size: 'defaul
431
442
  /** Everything inside the row — written once, for the same reason. Shared
432
443
  * inside the package like `menuItemClassName`: `CommandPalette` draws it
433
444
  * inside Base UI's `Autocomplete.Item`. Not exported from the index. */
434
- export function MenuItemBody({ label, children, size = 'default', description, aside, leading, trailing, hint, shortcut, submenu, destructive, selected }: Pick<MenuItemProps, 'label' | 'children' | 'size' | 'description' | 'aside' | 'leading' | 'trailing' | 'hint' | 'shortcut' | 'submenu' | 'destructive' | 'selected'>) {
445
+ export function MenuItemBody({ label, children, size = 'default', description, aside, leading, trailing, hint, shortcut, submenu, destructive, selected, shut = false }: Pick<MenuItemProps, 'label' | 'children' | 'size' | 'description' | 'aside' | 'leading' | 'trailing' | 'hint' | 'shortcut' | 'submenu' | 'destructive' | 'selected'> & { shut?: boolean }) {
446
+ // Shut, its words in the disabled colour, a destructive one's too.
447
+ const labelColour = shut ? 'text-text-disabled' : destructive ? 'text-error-default' : 'text-text-primary'
435
448
  const edge =
436
449
  trailing ??
437
450
  (shortcut ? (
@@ -449,15 +462,15 @@ export function MenuItemBody({ label, children, size = 'default', description, a
449
462
  <span className={cn('flex min-w-0 flex-1 flex-col', size === 'tall' && 'gap-[2px]')}>
450
463
  {aside ? (
451
464
  <span className="flex min-w-0 items-baseline gap-2">
452
- <span className={cn('truncate text-body-2', destructive ? 'text-error-default' : 'text-text-primary')}>{label}</span>
453
- <span className="shrink-0 text-caption text-text-muted">{aside}</span>
465
+ <span className={cn('truncate text-body-2', labelColour)}>{label}</span>
466
+ <span className={cn('shrink-0 text-caption', shut ? 'text-text-disabled' : 'text-text-muted')}>{aside}</span>
454
467
  </span>
455
468
  ) : (
456
- <span className={cn('truncate text-body-2', destructive ? 'text-error-default' : 'text-text-primary')}>
469
+ <span className={cn('truncate text-body-2', labelColour)}>
457
470
  {label}
458
471
  </span>
459
472
  )}
460
- {description && <span className="truncate text-caption text-text-secondary">{description}</span>}
473
+ {description && <span className={cn('truncate text-caption', shut ? 'text-text-disabled' : 'text-text-secondary')}>{description}</span>}
461
474
  </span>
462
475
  )}
463
476
  {(edge || hint) && (
@@ -482,7 +495,8 @@ export function MenuItemBody({ label, children, size = 'default', description, a
482
495
  )
483
496
  }
484
497
 
485
- export function MenuItem({ label, children, size = 'default', description, aside, leading, trailing, hint, shortcut, submenu, destructive, selected, className, ...props }: MenuItemProps) {
498
+ export function MenuItem({ label, children, size = 'default', description, aside, leading, trailing, hint, shortcut, submenu, destructive, selected, disabledReason, className, ...props }: MenuItemProps) {
499
+ const shut = !!disabledReason
486
500
  const body = (
487
501
  <MenuItemBody
488
502
  label={label}
@@ -496,11 +510,14 @@ export function MenuItem({ label, children, size = 'default', description, aside
496
510
  submenu={submenu}
497
511
  destructive={destructive}
498
512
  selected={selected}
513
+ shut={shut}
499
514
  >
500
515
  {children}
501
516
  </MenuItemBody>
502
517
  )
503
- const rowClassName = menuItemClassName({ size, selected, className })
518
+ const rowClassName = menuItemClassName({ size, selected, shut, className })
519
+ // Shut with its reason, the row is the reason's trigger, as Button is.
520
+ const withReason = (row: ReactElement) => (shut ? <TooltipTrigger label={disabledReason ?? ''}>{row}</TooltipTrigger> : row)
504
521
 
505
522
  /*
506
523
  * Inside a `Menu` the row is Base UI's `Menu.Item`: it joins the roving
@@ -521,13 +538,14 @@ export function MenuItem({ label, children, size = 'default', description, aside
521
538
  * than claiming none.
522
539
  */
523
540
  if (!useContext(MenuContext)) {
524
- return (
525
- <button type="button" className={rowClassName} {...props}>
541
+ // Shut: still a button the pointer and Tab reach, for its reason, but a press runs nothing.
542
+ return withReason(
543
+ <button type="button" className={rowClassName} {...props} {...(shut ? { 'aria-disabled': true, onClick: undefined } : {})}>
526
544
  {body}
527
- </button>
545
+ </button>,
528
546
  )
529
547
  }
530
- return (
548
+ return withReason(
531
549
  <BaseMenu.Item
532
550
  nativeButton
533
551
  render={<button type="button" />}
@@ -539,9 +557,12 @@ export function MenuItem({ label, children, size = 'default', description, aside
539
557
  handler facing a div signature. The element underneath is a
540
558
  `<button>`, which `Menu.test.tsx` pins. */
541
559
  {...(props as ComponentPropsWithRef<'div'>)}
560
+ /* Base UI's own disabled: the row stays where the arrow keys go (focusable when disabled), says
561
+ `aria-disabled`, and a press neither runs it nor closes the menu. */
562
+ disabled={props.disabled || shut}
542
563
  >
543
564
  {body}
544
- </BaseMenu.Item>
565
+ </BaseMenu.Item>,
545
566
  )
546
567
  }
547
568
 
package/src/MenuItem.mdx CHANGED
@@ -23,6 +23,17 @@ other two), `destructive` in the error colour, `selected` as the fill.
23
23
 
24
24
  <Canvas of={MenuItemStories.Tall} />
25
25
 
26
+ - **`disabledReason`**: a row shown but shut, saying why, as `Button`'s
27
+ does. Its words and its icon take the disabled colour, and it takes no
28
+ fill under the pointer or the arrow keys; the reason shows there instead,
29
+ on hover and where the arrow keys reach it. A press runs
30
+ nothing, and the menu stays open. For an action the reader should see
31
+ but cannot take right now; one they may never take is not offered.
32
+
33
+ <Canvas of={MenuItemStories.Shut} />
34
+
35
+ <Canvas of={MenuItemStories.ShutInAMenu} />
36
+
26
37
  ## When not
27
38
 
28
39
  - A single action that is not a row in a list → **Button**. Outside a
@@ -62,6 +73,7 @@ It does these by itself. Write none of them around it.
62
73
  | Is a row of its Menu: the Menu highlights it, walks to it with the arrow keys, and closes when it is chosen | a highlight or a key handler on the row | |
63
74
  | Opens its `submenu` with → and closes it with ← | a submenu of your own | |
64
75
  | Keeps its row's height in a scrolling column | `shrink-0` | |
76
+ | Shut with `disabledReason`: says why under the pointer and on the arrow keys, runs nothing, keeps the menu open | a tooltip round a row, a check in `onClick` | |
65
77
 
66
78
  ## Props
67
79