Skip to content
Closed
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
15 changes: 15 additions & 0 deletions src/components/editorAccessibility.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,20 @@ function normalizedAccessibilityValue(
return normalized ? normalized : undefined;
}

/** Reject runtime direction values outside Inkspan's public finite contract. */
function validateEditorTextDirection(
value: EditorTextDirection | undefined,
): void {
if (
value !== undefined &&
value !== 'ltr' &&
value !== 'rtl' &&
value !== 'auto'
) {
throw new RangeError('Editor text direction must be ltr, rtl, or auto.');
}
}

/**
* Normalize the shared visual and semantic empty-editor guidance.
*
Expand All @@ -61,6 +75,7 @@ export function normalizeEditorPlaceholder(
export function buildEditorAccessibilityAttributes(
options: EditorAccessibilityOptions,
): Record<string, string> {
validateEditorTextDirection(options.textDirection);
const placeholder = normalizeEditorPlaceholder(options.placeholder);
const languageTag = normalizedAccessibilityValue(options.languageTag);
const labelledBy = normalizedAccessibilityValue(options.ariaLabelledBy);
Expand Down
29 changes: 29 additions & 0 deletions src/components/editorAccessibilityRuntime.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { describe, expect, it } from 'vitest';
import { buildEditorAccessibilityAttributes } from './editorAccessibility.js';

describe('editor accessibility runtime contracts', () => {
it.each(['ltr', 'rtl', 'auto'] as const)(
'preserves the valid %s text direction',
(textDirection) => {
expect(
buildEditorAccessibilityAttributes({
defaultLabel: 'Editor',
editable: true,
textDirection,
}).dir,
).toBe(textDirection);
},
);

it('rejects a runtime text direction outside the public enumerated states', () => {
expect(() =>
buildEditorAccessibilityAttributes({
defaultLabel: 'Editor',
editable: true,
textDirection: 'sideways' as never,
}),
).toThrowError(
new RangeError('Editor text direction must be ltr, rtl, or auto.'),
);
});
});
Loading