Skip to content

Commit 22e9f30

Browse files
committed
fix(app): grow multiline question answers
1 parent 10e2edd commit 22e9f30

6 files changed

Lines changed: 49 additions & 7 deletions

File tree

‎packages/app/e2e/regression/session-request-docks.spec.ts‎

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ test("replies with predefined choices and a multiline custom answer", async ({ p
115115
const terminal = question.getByRole("checkbox", { name: "Terminal", exact: true })
116116
const custom = question.getByRole("checkbox", { name: "Type your own answer…", exact: true })
117117
const input = question.getByRole("textbox", { name: "Type your own answer…", exact: true })
118+
const customRow = question.locator('[data-slot="question-option"][data-custom="true"]')
118119
const cancellations: string[] = []
119120
page.on("request", (request) => {
120121
if (
@@ -149,6 +150,21 @@ test("replies with predefined choices and a multiline custom answer", async ({ p
149150
await expect(files).toBeChecked()
150151
await expect(terminal).toBeChecked()
151152

153+
await input.fill("first\nsecond\nthird\nfourth")
154+
await expect.poll(() => input.evaluate((el) => el.scrollHeight - el.clientHeight)).toBeLessThanOrEqual(1)
155+
await expect.poll(() => input.evaluate((el) => el.getBoundingClientRect().height)).toBeGreaterThan(52)
156+
await input.fill(Array.from({ length: 12 }, (_, index) => `line ${index + 1}`).join("\n"))
157+
await expect.poll(() => input.evaluate((el) => el.scrollHeight - el.clientHeight)).toBeGreaterThan(0)
158+
await expect.poll(() => input.evaluate((el) => el.getBoundingClientRect().height)).toBeLessThanOrEqual(124)
159+
expect(
160+
await input.evaluate((el) => {
161+
el.scrollTop = el.scrollHeight
162+
return el.scrollTop
163+
}),
164+
).toBeGreaterThan(0)
165+
166+
await input.fill("")
167+
await expect.poll(() => customRow.evaluate((el) => el.getBoundingClientRect().height)).toBe(40)
152168
await input.fill("alpha")
153169
await page.keyboard.insertText("\nbeta")
154170
await expect(input).toHaveValue("alpha\nbeta")
@@ -157,6 +173,17 @@ test("replies with predefined choices and a multiline custom answer", async ({ p
157173
await page.keyboard.insertText("gamma")
158174
await expect(input).toHaveValue("alpha\nbeta\ngamma")
159175
await input.dispatchEvent("keydown", { key: "Enter", isComposing: true })
176+
await expect(customRow).toHaveAttribute("data-editing", "true")
177+
await expect(input).toBeFocused()
178+
expect(
179+
await input.evaluate((el) => {
180+
const event = new KeyboardEvent("keydown", { key: "Enter", bubbles: true })
181+
Object.defineProperty(event, "keyCode", { value: 229 })
182+
el.dispatchEvent(event)
183+
return event.keyCode
184+
}),
185+
).toBe(229)
186+
await expect(customRow).toHaveAttribute("data-editing", "true")
160187
await expect(input).toBeFocused()
161188
await input.press("Enter")
162189
await expect(input).not.toBeFocused()
Binary file not shown.
-31.3 KB
Binary file not shown.
-31.1 KB
Binary file not shown.

‎packages/app/src/session/requests/session-question-dock.tsx‎

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,16 @@ export const SessionQuestionDock: Component<{ request: FormInfo; onSubmit: () =>
162162
setStore("answers", store.tab, next ? [next] : [])
163163
}
164164

165+
const resizeInput = (el: HTMLTextAreaElement) => {
166+
el.style.height = "0px"
167+
el.style.height = `${el.scrollHeight}px`
168+
}
169+
170+
createEffect(() => {
171+
input()
172+
if (customInput) resizeInput(customInput)
173+
})
174+
165175
const measure = () => {
166176
if (!root) return
167177

@@ -715,9 +725,12 @@ export const SessionQuestionDock: Component<{ request: FormInfo; onSubmit: () =>
715725
<Mark multi={multi()} picked={on()} />
716726
</button>
717727
<textarea
718-
ref={(el) => (customInput = el)}
728+
ref={(el) => {
729+
customInput = el
730+
resizeInput(el)
731+
}}
719732
class="question-custom-field"
720-
rows={2}
733+
rows={1}
721734
dir="auto"
722735
aria-label={customLabel()}
723736
placeholder={customLabel()}
@@ -745,7 +758,7 @@ export const SessionQuestionDock: Component<{ request: FormInfo; onSubmit: () =>
745758

746759
if ((e.metaKey || e.ctrlKey) && !e.altKey) return
747760

748-
if (e.key !== "Enter" || e.shiftKey || e.isComposing) return
761+
if (e.key !== "Enter" || e.shiftKey || e.isComposing || e.keyCode === 229) return
749762
e.preventDefault()
750763
commitCustom()
751764
}}

‎packages/session-ui/src/components/question-prompt.css‎

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,7 @@
288288
[data-slot="question-option"][data-custom="true"] {
289289
align-items: center;
290290
block-size: auto;
291-
min-block-size: 64px;
291+
min-block-size: 40px;
292292
padding-block: 6px;
293293
padding-inline: 10px;
294294

@@ -338,10 +338,11 @@
338338
flex: 1;
339339
inline-size: 100%;
340340
min-inline-size: 0;
341-
block-size: 52px;
342-
min-block-size: 52px;
341+
block-size: 28px;
342+
min-block-size: 28px;
343+
max-block-size: 124px;
343344
align-self: center;
344-
padding: 8px 0;
345+
padding: 6px 0;
345346
margin: 0;
346347
border: 0;
347348
border-radius: 6px;
@@ -350,6 +351,7 @@
350351
outline: none;
351352
opacity: 1;
352353
transition: none;
354+
overflow-y: auto;
353355

354356
resize: none;
355357
font-family: var(--v2-font-family-sans);

0 commit comments

Comments
 (0)