@estiva-app/ui 0.98.0 → 0.98.1

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": "@estiva-app/ui",
3
- "version": "0.98.0",
3
+ "version": "0.98.1",
4
4
  "description": "Estiva's design tokens (the contract) and a small set of primitives (a convenience) for every Estiva app.",
5
5
  "type": "module",
6
6
  "license": "MIT",
package/registry.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "kind": "package",
5
5
  "repo": "estiva-ui",
6
6
  "package": "@estiva-app/ui",
7
- "packageVersion": "0.98.0",
7
+ "packageVersion": "0.98.1",
8
8
  "exports": 229,
9
9
  "typeExports": 234,
10
10
  "files": null
@@ -8155,6 +8155,12 @@
8155
8155
  "takes": "true/false",
8156
8156
  "required": false,
8157
8157
  "note": "Some reactions may be missing: the read was cut short."
8158
+ },
8159
+ {
8160
+ "name": "noun",
8161
+ "takes": "text",
8162
+ "required": false,
8163
+ "note": "What the app calls what is said, in the plural: \"messages\" in Peek."
8158
8164
  }
8159
8165
  ],
8160
8166
  "variants": [],
@@ -64,6 +64,7 @@ import { ConversationCard } from '@estiva-app/ui'
64
64
  | It does | So you never write | Refused when written by hand |
65
65
  |---|---|---|
66
66
  | Shows its actions while pointed at, and holds them while a menu is open | hover state and an outside-click check | |
67
+ | A card that opens on a press is a Tab stop: reaching it shows its actions, Enter or Space opens it | a `tabIndex` and a key handler | |
67
68
  | Asks before it deletes | a confirm dialog | |
68
69
  | Opens the Resolve dialog, and closes it once resolved | a dialog and its open state | |
69
70
  | Says it is resolved, with who and the note, and hides nothing of it | a resolved line or chip of your own | |
@@ -157,3 +157,43 @@ describe('ReplyCard', () => {
157
157
  expect(onDelete).toHaveBeenCalledOnce()
158
158
  })
159
159
  })
160
+
161
+ describe('ConversationCard, by the keyboard (Peek’s review, 1 November)', () => {
162
+ it('a card that opens on a press is a Tab stop: reaching it shows the strip, and Enter opens it', async () => {
163
+ const user = userEvent.setup()
164
+ const opened = vi.fn()
165
+ render(
166
+ <ConversationCard author={ONE} time="11:08 AM" onClick={opened} onReply={() => {}}>
167
+ A comment with nothing focusable in it
168
+ </ConversationCard>,
169
+ )
170
+ await user.tab()
171
+ const card = document.activeElement as HTMLElement
172
+ expect(card.textContent).toContain('A comment with nothing focusable in it')
173
+ expect(screen.getByRole('button', { name: 'Reply' })).toBeTruthy()
174
+ fireEvent.keyDown(card, { key: 'Enter' })
175
+ expect(opened).toHaveBeenCalledOnce()
176
+ fireEvent.keyDown(card, { key: ' ' })
177
+ expect(opened).toHaveBeenCalledTimes(2)
178
+ })
179
+
180
+ it('a key in a link inside it is the link’s, not a press on the card', () => {
181
+ const opened = vi.fn()
182
+ render(
183
+ <ConversationCard author={ONE} time="11:08 AM" onClick={opened}>
184
+ <a href="#somewhere">a link</a>
185
+ </ConversationCard>,
186
+ )
187
+ fireEvent.keyDown(screen.getByRole('link', { name: 'a link' }), { key: 'Enter' })
188
+ expect(opened).not.toHaveBeenCalled()
189
+ })
190
+
191
+ it('a card with nothing to open is no Tab stop', () => {
192
+ const { container } = render(
193
+ <ConversationCard author={ONE} time="11:08 AM" readOnly>
194
+ Nothing to open
195
+ </ConversationCard>,
196
+ )
197
+ expect(container.querySelector('[tabindex="0"]')).toBeNull()
198
+ })
199
+ })
@@ -317,6 +317,19 @@ export function ConversationCard(props: ConversationCardProps) {
317
317
  attention={attentionOf(isNew || !!replies?.isNew, urgent, inThreadCard)}
318
318
  className={cn('relative', className)}
319
319
  onClick={press && !isEditing && !overlay ? (e) => pressed(e, press) : undefined}
320
+ // A card that opens on a press is reached by the keyboard too: Tab stops on it, which shows its strip, and Enter or
321
+ // Space opens it. Only the card's own focus: a key in a link, a button or a field inside it is theirs. Before, a
322
+ // comment with nothing focusable in it (no replies, no link) could not be opened without a pointer.
323
+ tabIndex={press && !isEditing ? 0 : undefined}
324
+ onKeyDown={
325
+ press && !isEditing && !overlay
326
+ ? (e) => {
327
+ if (e.target !== e.currentTarget || (e.key !== 'Enter' && e.key !== ' ')) return
328
+ e.preventDefault()
329
+ press()
330
+ }
331
+ : undefined
332
+ }
320
333
  onMouseEnter={() => setHovered(true)}
321
334
  onMouseLeave={() => {
322
335
  if (picking || menuOpen) return
@@ -26,6 +26,7 @@ import { ReactionHorizon } from '@estiva-app/ui'
26
26
  ```
27
27
 
28
28
  - `limit`, `omitted` and `cut` are the app's to count.
29
+ - `noun` is what the app calls what is said, in the plural: "messages" in Peek. "comments" by default.
29
30
 
30
31
  ## What it owns
31
32
 
@@ -0,0 +1,23 @@
1
+ // @vitest-environment jsdom
2
+ import { afterEach, describe, expect, it } from 'vitest'
3
+ import { cleanup, render, screen } from '@testing-library/react'
4
+ import { ReactionHorizon } from './ReactionHorizon'
5
+
6
+ afterEach(cleanup)
7
+
8
+ describe('ReactionHorizon', () => {
9
+ it('says how far back reactions are read, in the kit’s words', () => {
10
+ render(<ReactionHorizon limit={100} omitted={3} />)
11
+ expect(screen.getByText(/the latest 100 comments and replies here\. 3 older ones were not checked\./)).toBeTruthy()
12
+ })
13
+
14
+ it('in the app’s own noun: Peek’s messages', () => {
15
+ render(<ReactionHorizon limit={100} omitted={1} noun="messages" />)
16
+ expect(screen.getByText(/the latest 100 messages and replies here\. 1 older one was not checked\./)).toBeTruthy()
17
+ })
18
+
19
+ it('draws nothing when every one was checked and the read was whole', () => {
20
+ const { container } = render(<ReactionHorizon limit={100} omitted={0} />)
21
+ expect(container.textContent).toBe('')
22
+ })
23
+ })
@@ -5,19 +5,21 @@ export interface ReactionHorizonProps {
5
5
  omitted: number
6
6
  /** Some reactions may be missing: the read was cut short. */
7
7
  cut?: boolean
8
+ /** What the app calls what is said, in the plural: "messages" in Peek. Default "comments". */
9
+ noun?: string
8
10
  }
9
11
 
10
12
  /**
11
13
  * The line that says reactions are read only so far back, and how many older comments were not checked. Nothing is
12
14
  * drawn when every one was. Peek's, moved with the conversation.
13
15
  */
14
- export function ReactionHorizon({ limit, omitted, cut = false }: ReactionHorizonProps) {
16
+ export function ReactionHorizon({ limit, omitted, cut = false, noun = 'comments' }: ReactionHorizonProps) {
15
17
  if (omitted <= 0 && !cut) return null
16
18
  return (
17
19
  <p className="text-caption text-text-muted">
18
20
  {omitted > 0 && (
19
21
  <>
20
- Reactions are shown for the latest {limit} comments and replies here. {omitted} older {omitted === 1 ? 'one was' : 'ones were'} not checked.
22
+ Reactions are shown for the latest {limit} {noun} and replies here. {omitted} older {omitted === 1 ? 'one was' : 'ones were'} not checked.
21
23
  </>
22
24
  )}
23
25
  {omitted > 0 && cut && ' '}