Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 14 additions & 6 deletions packages/devknobs/src/grab/tray.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export const TRAY_CSS = `
flex-direction: column;
gap: 6px;
box-sizing: border-box;
width: min(380px, calc(100vw - 32px));
width: min(320px, calc(100vw - 32px));
max-height: 40vh;
padding: 6px;
transform: translateX(-50%);
Expand Down Expand Up @@ -97,14 +97,19 @@ export const TRAY_CSS = `
all: unset;
display: block;
box-sizing: border-box;
flex: none;
width: 100%;
min-height: 24px;
max-height: 136px;
padding: 4px 6px;
overflow-y: auto;
field-sizing: content;
color: inherit;
background: var(--field);
border-radius: 8px;
font: inherit;
white-space: pre-wrap;
resize: none;
resize: vertical;
}
.tray textarea::placeholder { color: var(--quiet); }
.tray textarea:focus-visible, .tray button:focus-visible {
Expand Down Expand Up @@ -132,9 +137,6 @@ export const TRAY_CSS = `
.tray .hint {
flex: 1 1 auto;
min-width: 0;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
color: var(--quiet);
font-size: 11px;
}
Expand Down Expand Up @@ -197,7 +199,13 @@ export function createTray(options: TrayOptions): Tray {
node.setAttribute("aria-label", "Picked elements");
const list = element("div", "list");
const note = element("textarea");
note.rows = 2;
note.rows = 1;
if (typeof CSS === "undefined" || !CSS.supports("field-sizing", "content")) {
note.addEventListener("input", () => {
note.style.height = "auto";
note.style.height = `${note.scrollHeight}px`;
});
}
note.placeholder = "Note";
note.setAttribute("aria-label", "Note");
const foot = element("div", "foot");
Expand Down
9 changes: 8 additions & 1 deletion packages/devknobs/test/grab-tray.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ describe("TRAY_CSS", () => {
test("keeps the tray fixed, bounded and still with reduced motion", () => {
expect(TRAY_CSS).toContain("position: fixed;");
expect(TRAY_CSS).toContain("max-height: 40vh;");
expect(TRAY_CSS).toContain("width: min(380px, calc(100vw - 32px));");
expect(TRAY_CSS).toContain("width: min(320px, calc(100vw - 32px));");
expect(TRAY_CSS).toContain("env(safe-area-inset-bottom");
expect(TRAY_CSS).toContain("prefers-reduced-motion: reduce");
});
Expand All @@ -18,4 +18,11 @@ describe("TRAY_CSS", () => {
test("keeps the list's column to the tray's width, so a long label never pushes a row's start out", () => {
expect(TRAY_CSS).toContain("grid-template-columns: minmax(0, 1fr);");
});

test("grows the note with its text up to a cap, and lets it be dragged taller", () => {
expect(TRAY_CSS).toContain("field-sizing: content;");
expect(TRAY_CSS).toContain("max-height: 136px;");
expect(TRAY_CSS).toContain("resize: vertical;");
expect(TRAY_CSS).not.toContain("resize: none;");
});
});
Loading