sitesmith: readable form inputs on dark sections + sRGB color-mix() in contrast repair
Eval 2026-11-01 (ttm-likes): a ContactForm on a dark band had dark typed text
and UA-grey placeholders on a color-mix() input surface, and its inputBorder
"1px solid X" came out as the invalid "1px solid 1px solid X".
- ContactForm: new inputTextColor prop (typed text); placeholders now follow
the input's own text colour via a scoped form[data-wsb-form] ::placeholder
rule (export + editor canvas); an inputBorder that is a whole border is used
as-is. Without inputTextColor the legacy derivation is unchanged.
- contrast repair: resolves opaque color-mix(in srgb, A p%, B) surfaces (the
brief prescribes these tints; translucent / other spaces stay unchecked),
checks ContactForm labelColor against its section and the derived input text
colour against an explicitly set inputBg, writing inputTextColor on failure.
- catalog generator: (rebased onto main 01a78c9, which already omits the
clock-derived Countdown.targetDate default via VOLATILE_DEFAULTS + the
date-frozen drift test; this commit's duplicate inline check was dropped.)
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
0c9faf0495
commit
ed50732d58
5 files changed
+137
-11
No files matched your search
@@ -311,3 +311,27 @@ describe('ContactForm.toHtml design tokens (#44)', () => {
|
||||
for (const hex of ["#ef4444", "#374151", "#d1d5db", "#ffffff"]) expect(lower, `old ${hex}`).not.toContain(hex);
|
||||
});
|
||||
});
|
||||
|
||||
describe('ContactForm.toHtml dark-aware inputs (eval 2026-11-01)', () => {
|
||||
const fields = [{ type: 'text', label: 'Name', name: 'name', placeholder: 'Your name', required: true }];
|
||||
test('inputTextColor sets the typed text colour; placeholders follow it (currentColor) via a scoped rule', () => {
|
||||
const { html } = toHtml({ fields, inputBg: '#1b1530', inputTextColor: '#f5f3ff' }, '', 'n1');
|
||||
expect(html).toMatch(/<input[^>]*style="[^"]*color:#f5f3ff/);
|
||||
expect(html).toMatch(/<form[^>]*data-wsb-form/);
|
||||
expect(html).toContain('<style>form[data-wsb-form] ::placeholder{color:currentColor;opacity:.7}</style>');
|
||||
});
|
||||
test('without inputTextColor the old derivation stays (light stored surface -> legacy dark text)', () => {
|
||||
expect(toHtml({ fields, inputBg: '#ffffff' }, '').html).toMatch(/<input[^>]*color:#1f2937/);
|
||||
expect(toHtml({ fields }, '').html).toMatch(/<input[^>]*color:var\(--wsb-text\)/);
|
||||
});
|
||||
test('an inputBorder written as a whole border ("1px solid X") is used as-is, not doubled into "1px solid 1px solid X"', () => {
|
||||
const { html } = toHtml({ fields, inputBorder: '1px solid color-mix(in srgb, var(--wsb-secondary) 45%, transparent)' }, '');
|
||||
expect(html).not.toContain('1px solid 1px solid');
|
||||
expect(html).toContain('border:1px solid color-mix(in srgb, var(--wsb-secondary) 45%, transparent)');
|
||||
expect(toHtml({ fields, inputBorder: '#334155' }, '').html).toContain('border:1px solid #334155');
|
||||
});
|
||||
test('a hostile inputTextColor cannot break out of the style attribute', () => {
|
||||
const { html } = toHtml({ fields, inputTextColor: 'red;}"><script>alert(1)</script>' }, '');
|
||||
expect(html).not.toContain('<script>');
|
||||
});
|
||||
});
|
||||
@@ -15,6 +15,14 @@ import { textOnSurface } from '../../utils/color';
|
||||
ContactForm was introduced, so legacy nodes carry their own '#374151'.) */
|
||||
const LEGACY_INPUT_TEXT = '#1f2937';
|
||||
|
||||
/** Placeholders follow the input's own text colour, so they stay readable on dark inputs too (the UA grey did
|
||||
* not). Scoped to these forms; emitted once per form in export, once globally in the editor canvas. */
|
||||
export const FORM_PLACEHOLDER_CSS = 'form[data-wsb-form] ::placeholder{color:currentColor;opacity:.7}';
|
||||
|
||||
/** `inputBorder` is a colour; a model sometimes writes a whole border ("1px solid X"): use that as-is. */
|
||||
export const inputBorderCss = (v: string): string =>
|
||||
/\b(?:solid|dashed|dotted|double|groove|ridge|inset|outset|none|hidden)\b/i.test(v) ? v : `1px solid ${v}`;
|
||||
|
||||
// The allowlist enforced at export time lives in `sanitizeInputType`
|
||||
// (utils/escape.ts) -- this union is a superset (it also covers 'textarea'
|
||||
// and 'select', which take their own render branches instead of an
|
||||
@@ -42,6 +50,8 @@ interface ContactFormProps {
|
||||
style?: CSSProperties;
|
||||
labelColor?: string;
|
||||
inputBg?: string;
|
||||
/** Typed text (and, via currentColor, placeholder) colour in the inputs. Absent = derived from inputBg (legacy rule). */
|
||||
inputTextColor?: string;
|
||||
inputBorder?: string;
|
||||
recipientEmail?: string;
|
||||
thankYouUrl?: string;
|
||||
@@ -82,6 +92,7 @@ export const ContactForm: UserComponent<ContactFormProps> = ({
|
||||
style = {},
|
||||
labelColor = tokenRef('text'),
|
||||
inputBg = tokenRef('bg'),
|
||||
inputTextColor,
|
||||
inputBorder = tokenRef('border'),
|
||||
}) => {
|
||||
const {
|
||||
@@ -96,10 +107,10 @@ export const ContactForm: UserComponent<ContactFormProps> = ({
|
||||
padding: '10px 14px',
|
||||
fontSize: '14px',
|
||||
fontFamily: 'Inter, sans-serif',
|
||||
border: `1px solid ${inputBorder}`,
|
||||
border: inputBorderCss(inputBorder),
|
||||
borderRadius: '6px',
|
||||
backgroundColor: inputBg,
|
||||
color: textOnSurface(inputBg, LEGACY_INPUT_TEXT, tokenRef('text')),
|
||||
color: inputTextColor || textOnSurface(inputBg, LEGACY_INPUT_TEXT, tokenRef('text')),
|
||||
boxSizing: 'border-box',
|
||||
outline: 'none',
|
||||
};
|
||||
@@ -109,6 +120,7 @@ export const ContactForm: UserComponent<ContactFormProps> = ({
|
||||
ref={(ref: HTMLFormElement | null): void => { if (ref) connect(drag(ref)); }}
|
||||
action={formAction}
|
||||
method="POST"
|
||||
data-wsb-form=""
|
||||
onSubmit={(e) => e.preventDefault()}
|
||||
style={{
|
||||
padding: '32px',
|
||||
@@ -231,7 +243,8 @@ ContactForm.craft = {
|
||||
const labelColor = cssValue(props.labelColor) || tokenRef('text');
|
||||
const inputBg = cssValue(props.inputBg) || tokenRef('bg');
|
||||
const inputBorder = cssValue(props.inputBorder) || tokenRef('border');
|
||||
const inputStyleStr = `width:100%;padding:10px 14px;font-size:14px;font-family:Inter,sans-serif;border:1px solid ${inputBorder};border-radius:6px;background-color:${inputBg};color:${textOnSurface(inputBg, LEGACY_INPUT_TEXT, tokenRef('text'))};box-sizing:border-box;outline:none`;
|
||||
const inputText = cssValue(props.inputTextColor) || textOnSurface(inputBg, LEGACY_INPUT_TEXT, tokenRef('text'));
|
||||
const inputStyleStr = `width:100%;padding:10px 14px;font-size:14px;font-family:Inter,sans-serif;border:${inputBorderCss(inputBorder)};border-radius:6px;background-color:${inputBg};color:${inputText};box-sizing:border-box;outline:none`;
|
||||
|
||||
const fieldsHtml = (props.fields || defaultFields).map((field, i) => {
|
||||
const reqStar = field.required ? `<span style="color:${tokenRef('error')};margin-left:2px">*</span>` : '';
|
||||
@@ -285,8 +298,8 @@ ContactForm.craft = {
|
||||
const successAttr = props.successMessage ? ` data-whp-success-message="${escapeAttr(props.successMessage)}"` : '';
|
||||
|
||||
return {
|
||||
html: `${marker}<form action="${actionAttr}" method="POST"${successAttr}${formStyle ? ` style="${formStyle}"` : ''}>
|
||||
html: `${marker}<form action="${actionAttr}" method="POST" data-wsb-form${successAttr}${formStyle ? ` style="${formStyle}"` : ''}>
|
||||
${honeypot ? ` ${honeypot}\n` : ''}${fieldsHtml ? ` ${fieldsHtml}\n` : ''} <button type="submit"${btnStyle ? ` style="${btnStyle}"` : ''}>${escapeHtml(props.submitText || 'Send Message')}</button>
|
||||
</form>`,
|
||||
</form><style>${FORM_PLACEHOLDER_CSS}</style>`,
|
||||
};
|
||||
};
|
||||
Reference in new issue
Block a user