|
| 1 | +/** |
| 2 | + * ObjectUI |
| 3 | + * Copyright (c) 2024-present ObjectStack Inc. |
| 4 | + * |
| 5 | + * This source code is licensed under the MIT license found in the |
| 6 | + * LICENSE file in the root directory of this source tree. |
| 7 | + */ |
| 8 | + |
| 9 | +/** |
| 10 | + * objectstack-ai/objectstack#27417 — the markdown / html / richtext editor's |
| 11 | + * placeholder is prose, not source. |
| 12 | + * |
| 13 | + * The textarea is `font-mono` because what a person types into it is markdown |
| 14 | + * or HTML source. Its placeholder inherited the same face, so a public form's |
| 15 | + * "Describe your request" read as code. The placeholder now takes the sans |
| 16 | + * stack and the typed source keeps mono. |
| 17 | + * |
| 18 | + * jsdom computes no `::placeholder` style, so this pins the utility pair on |
| 19 | + * the control; the computed `font-family` of the placeholder was measured in |
| 20 | + * real Chromium on the console's public form page (the PR's Verification). |
| 21 | + */ |
| 22 | + |
| 23 | +import { describe, it, expect } from 'vitest'; |
| 24 | +import { render, screen } from '@testing-library/react'; |
| 25 | +import '@testing-library/jest-dom'; |
| 26 | +import type { HtmlFieldMetadata, MarkdownFieldMetadata, RichtextFieldMetadata } from '@object-ui/types'; |
| 27 | + |
| 28 | +import { RichTextField } from '../RichTextField'; |
| 29 | + |
| 30 | +const FIELDS: Array<MarkdownFieldMetadata | HtmlFieldMetadata | RichtextFieldMetadata> = [ |
| 31 | + { type: 'markdown', name: 'notes', placeholder: 'Describe your request' }, |
| 32 | + { type: 'html', name: 'body', placeholder: 'Describe your request' }, |
| 33 | + { type: 'richtext', name: 'doc', placeholder: 'Describe your request' }, |
| 34 | +]; |
| 35 | + |
| 36 | +describe('RichTextField — the placeholder takes the sans stack, the source stays mono (#27417)', () => { |
| 37 | + it.each(FIELDS.map((f) => [f.type, f] as const))('%s', (_type, field) => { |
| 38 | + render(<RichTextField value="" onChange={() => {}} field={field} />); |
| 39 | + const box = screen.getByPlaceholderText('Describe your request'); |
| 40 | + expect(box).toHaveClass('placeholder:font-sans'); |
| 41 | + expect(box).toHaveClass('font-mono'); |
| 42 | + }); |
| 43 | +}); |
0 commit comments