Skip to content

🎥 Make videos programmatically with React

Studio: Use icon button for caption line breaks

Jonny Burger964394f332a5
diff --git a/packages/example/e2e/captions-inspector.test.mts b/packages/example/e2e/captions-inspector.test.mts
index 46c662de06..1a06792474 100644
--- a/packages/example/e2e/captions-inspector.test.mts
+++ b/packages/example/e2e/captions-inspector.test.mts
@@ -37,16 +37,26 @@ test.describe('captions inspector', () => {
const captionsSequence = page
.getByText('<AnimatedCaptions>', {exact: true})
.first();
- const lineBreakAfterFirstCaption = page.getByRole('checkbox', {
- name: 'Line break after caption 1',
+ const lineBreakAfterFirstCaption = page.getByRole('button', {
+ name: 'Add line break after caption 1',
exact: true,
});
await expect(async () => {
await captionsSequence.click();
await expect(lineBreakAfterFirstCaption).toBeVisible({timeout: 1_000});
}).toPass({timeout: 30_000});
+ await expect(lineBreakAfterFirstCaption).toHaveAttribute(
+ 'aria-pressed',
+ 'false',
+ );
- await lineBreakAfterFirstCaption.check();
+ await lineBreakAfterFirstCaption.click();
+ await expect(
+ page.getByRole('button', {
+ name: 'Remove line break after caption 1',
+ exact: true,
+ }),
+ ).toHaveAttribute('aria-pressed', 'true');
await expect
.poll(() => {
return fs
diff --git a/packages/studio/src/components/CaptionTextEditor.tsx b/packages/studio/src/components/CaptionTextEditor.tsx
index a564ee22c7..9798004d35 100644
--- a/packages/studio/src/components/CaptionTextEditor.tsx
+++ b/packages/studio/src/components/CaptionTextEditor.tsx
@@ -1,7 +1,15 @@
import type {Caption} from '@remotion/captions';
import React, {useCallback, useEffect, useMemo, useRef} from 'react';
-import {BACKGROUND, LIGHT_TEXT, LINE_COLOR, WHITE} from '../helpers/colors';
-import {Checkbox} from './Checkbox';
+import {
+ BACKGROUND,
+ BLUE,
+ LIGHT_TEXT,
+ LINE_COLOR,
+ WHITE,
+} from '../helpers/colors';
+import {FOCUS_VISIBLE_ONLY_CLASS_NAME} from '../helpers/hoverable';
+import {EnterIcon} from '../icons/enter';
+import {InlineAction} from './InlineAction';
import {RemotionInput} from './NewComposition/RemInput';
const container: React.CSSProperties = {
@@ -23,28 +31,10 @@ const row: React.CSSProperties = {
borderBottom: `1px solid ${LINE_COLOR}`,
display: 'grid',
gap: 8,
- gridTemplateColumns: '100px minmax(0, 1fr) 18px',
+ gridTemplateColumns: '100px minmax(0, 1fr) 24px',
padding: '5px 12px',
};
-const lineBreakControl: React.CSSProperties = {
- display: 'flex',
- height: 18,
- position: 'relative',
- width: 18,
-};
-
-const visuallyHidden: React.CSSProperties = {
- clip: 'rect(0, 0, 0, 0)',
- height: 1,
- margin: -1,
- overflow: 'hidden',
- padding: 0,
- position: 'absolute',
- whiteSpace: 'nowrap',
- width: 1,
-};
-
const timing: React.CSSProperties = {
color: LIGHT_TEXT,
fontFamily: 'monospace',
@@ -168,6 +158,11 @@ export const CaptionTextEditor: React.FC<{
<div ref={listRef} style={list}>
{captions.length === 0 ? <div style={empty}>No captions</div> : null}
{captionRows.map(({caption, key}, index) => {
+ const hasLineBreakAfter = Boolean(caption.lineBreakAfter);
+ const lineBreakTitle = hasLineBreakAfter
+ ? `Remove line break after caption ${index + 1}`
+ : `Add line break after caption ${index + 1}`;
+
return (
<div key={key} style={row}>
<div style={timing}>
@@ -219,21 +214,25 @@ export const CaptionTextEditor: React.FC<{
}}
value={caption.text}
/>
- <label style={lineBreakControl} title="Line break after">
- <span style={visuallyHidden}>
- Line break after caption {index + 1}
- </span>
- <Checkbox
- checked={Boolean(caption.lineBreakAfter)}
- disabled={readOnly}
- name={`caption-line-break-after-${index}`}
- onChange={(event) => {
- updateLineBreakAfter(index, event.target.checked);
- commitPending();
- }}
- variant="small"
- />
- </label>
+ <InlineAction
+ aria-pressed={hasLineBreakAfter}
+ className={FOCUS_VISIBLE_ONLY_CLASS_NAME}
+ disabled={readOnly}
+ onClick={() => {
+ updateLineBreakAfter(index, !hasLineBreakAfter);
+ commitPending();
+ }}
+ renderAction={(color) => (
+ <EnterIcon
+ aria-hidden="true"
+ color={hasLineBreakAfter ? BLUE : color}
+ focusable="false"
+ style={{height: 16, width: 16}}
+ />
+ )}
+ title={lineBreakTitle}
+ variant={null}
+ />
</div>
);
})}
diff --git a/packages/studio/src/icons/enter.tsx b/packages/studio/src/icons/enter.tsx
new file mode 100644
index 0000000000..acc92382b1
--- /dev/null
+++ b/packages/studio/src/icons/enter.tsx
@@ -0,0 +1,16 @@
+import type {SVGProps} from 'react';
+
+// Font Awesome Pro v7.3.1, Copyright 2026 Fonticons, Inc.
+// https://fontawesome.com/license (Commercial License)
+export const EnterIcon: React.FC<
+ SVGProps<SVGSVGElement> & {readonly color: string}
+> = ({color, ...props}) => {
+ return (
+ <svg {...props} xmlns="http://www.w3.org/2000/svg" viewBox="0 0 640 640">
+ <path
+ fill={color}
+ d="M544 144C544 135.2 551.2 128 560 128C568.8 128 576 135.2 576 144L576 240C576 293 533 336 480 336L118.6 336L235.3 452.7C241.5 458.9 241.5 469.1 235.3 475.3C229.1 481.5 218.9 481.5 212.7 475.3L68.7 331.3C65.7 328.3 64 324.2 64 320C64 315.8 65.7 311.7 68.7 308.7L212.7 164.7C218.9 158.5 229.1 158.5 235.3 164.7C241.5 170.9 241.5 181.1 235.3 187.3L118.6 304L480 304C515.3 304 544 275.3 544 240L544 144z"
+ />
+ </svg>
+ );
+};