Overview
The formatStrikeThrough inputType is triggered when the user applies strikethrough formatting (typically via context menu or programmatically). The browser wraps selected text in a <s> or <strike> element.
Basic Behavior
Scenario: Text selected within paragraph
Before (Text selected)
After formatStrikeThrough (Chrome/Edge)
After formatStrikeThrough (Firefox)
Browser-Specific Differences
Element Used for Strikethrough
Chrome/Edge
- Uses
<s>element
Firefox
- Uses
<strike>element (deprecated HTML)
IME Composition + formatStrikeThrough
⚠️ Critical Issue
During IME composition, formatStrikeThrough may not work as expected. On macOS with Korean IME, the event may not fire; insertCompositionText may fire instead.
See formatBold for detailed workarounds.
Editor-Specific Handling
Different editor frameworks handle strikethrough formatting similarly to other text formatting. Here's how major editors implement formatStrikeThrough:
Strikethrough Formatting
Slate uses Transforms.setNodes() to toggle strikethrough marks:
import { Editor, Transforms, Text } from 'slate';
function isStrikethroughActive(editor: Editor) {
const marks = Editor.marks(editor);
return marks?.strikethrough === true;
}
function handleFormatStrikethrough(editor: Editor) {
const isActive = isStrikethroughActive(editor);
Transforms.setNodes(
editor,
{ strikethrough: !isActive },
{ match: n => Text.isText(n), split: true }
);
}
element.addEventListener('beforeinput', (e) => {
if (e.inputType === 'formatStrikeThrough') {
e.preventDefault();
handleFormatStrikethrough(editor);
}
});
- Mark-based: Formatting stored as
{ strikethrough: true }on text nodes. - Same pattern: Uses identical Transforms API as other formatting marks.
Strikethrough Formatting
ProseMirror uses toggleMark with strikethrough mark:
import { toggleMark } from 'prosemirror-commands';
import { schema } from './schema';
function handleFormatStrikethrough(state, dispatch) {
return toggleMark(schema.marks.strikethrough)(state, dispatch);
}
view.dom.addEventListener('beforeinput', (e) => {
if (e.inputType === 'formatStrikeThrough') {
e.preventDefault();
const { state, dispatch } = view;
if (handleFormatStrikethrough(state, dispatch)) {
// Handled
}
}
});
- Mark system: Uses
schema.marks.strikethroughmark type. - Same command: Uses
toggleMark()like other formatting.
Strikethrough Formatting
Draft.js uses RichUtils.toggleInlineStyle() with STRIKETHROUGH:
import { EditorState, RichUtils } from 'draft-js';
function handleFormatStrikethrough(editorState) {
return RichUtils.toggleInlineStyle(editorState, 'STRIKETHROUGH');
}
function handleKeyCommand(command) {
if (command === 'strikethrough') {
const newState = handleFormatStrikethrough(editorState);
setEditorState(newState);
return 'handled';
}
return 'not-handled';
}
- Inline style: Uses
'STRIKETHROUGH'style string. - Same utility: Uses
RichUtils.toggleInlineStylelike other formatting.