🎥 Make videos programmatically with React
escape hook
Jonny Burgerdf255f2d90e3
diff --git a/packages/cli/src/editor/components/NewComposition/InputDragger.tsx b/packages/cli/src/editor/components/NewComposition/InputDragger.tsxindex 8a1c911e78..dfbe001dcc 100644--- a/packages/cli/src/editor/components/NewComposition/InputDragger.tsx+++ b/packages/cli/src/editor/components/NewComposition/InputDragger.tsx@@ -9,7 +9,9 @@ import React, {useState,} from 'react';import {interpolate} from 'remotion';+import {noop} from '../../helpers/noop';import {getClickLock, setClickLock} from '../../state/input-dragger-click-lock';+import {HigherZIndex} from '../../state/z-index';import {inputBaseStyle, RemotionInput} from './RemInput';type Props = InputHTMLAttributes<HTMLInputElement> & {@@ -119,16 +121,18 @@ export const InputDragger: React.FC<Props> = ({if (inputFallback) {return (- <RemotionInput- ref={fallbackRef}- autoFocus- onKeyPress={onKeyPress}- onBlur={onBlur}- value={value}- min={_min}- step={_step}- {...props}- />+ <HigherZIndex onEscape={onBlur} onOutsideClick={noop}>+ <RemotionInput+ ref={fallbackRef}+ autoFocus+ onKeyPress={onKeyPress}+ onBlur={onBlur}+ value={value}+ min={_min}+ step={_step}+ {...props}+ />+ </HigherZIndex>);}diff --git a/packages/cli/src/editor/components/NewComposition/NewCompDuration.tsx b/packages/cli/src/editor/components/NewComposition/NewCompDuration.tsxindex 9dd4e54d24..a1e78f4186 100644--- a/packages/cli/src/editor/components/NewComposition/NewCompDuration.tsx+++ b/packages/cli/src/editor/components/NewComposition/NewCompDuration.tsx@@ -1,7 +1,9 @@import React, {ChangeEventHandler, useCallback} from 'react';+import {validateCompositionDuration} from '../../helpers/validate-new-comp-data';import {Row} from '../layout';import {InputDragger} from './InputDragger';import {inputArea, leftLabel, rightLabel} from './new-comp-layout';+import {ValidationMessage} from './ValidationMessage';const label: React.CSSProperties = {fontSize: 13,@@ -16,7 +18,7 @@ export const NewCompDuration: React.FC<{}> = ({durationInFrames, setDurationInFrames, fps}) => {const onDurationInFramesChanged: ChangeEventHandler<HTMLInputElement> = useCallback((e) => {- setDurationInFrames(e.target.value);+ setDurationInFrames(String(Number(e.target.value)));},[setDurationInFrames]);@@ -28,6 +30,8 @@ export const NewCompDuration: React.FC<{[setDurationInFrames]);+ const compDurationErrMessage = validateCompositionDuration(durationInFrames);+return (<div><label>@@ -39,10 +43,15 @@ export const NewCompDuration: React.FC<{value={durationInFrames}onChange={onDurationInFramesChanged}placeholder="Duration (frames)"- name="height"+ name="durationInFrames"min={1}+ step={1}+ max={100000000}onValueChange={onDurationChangedDirectly}/>+ {compDurationErrMessage ? (+ <ValidationMessage message={compDurationErrMessage} />+ ) : null}</div><span style={rightLabel}>{(Number(durationInFrames) / Number(fps)).toFixed(2)}secdiff --git a/packages/cli/src/editor/components/NewComposition/NewComposition.tsx b/packages/cli/src/editor/components/NewComposition/NewComposition.tsxindex ee3d1d0319..3bd6605580 100644--- a/packages/cli/src/editor/components/NewComposition/NewComposition.tsx+++ b/packages/cli/src/editor/components/NewComposition/NewComposition.tsx@@ -288,6 +288,7 @@ export const NewComposition: React.FC<{initialCompType: CompType}> = ({name="width"step={2}min={2}+ max={100000000}onValueChange={onWidthDirectlyChanged}/>{compWidthErrMessage ? (@@ -312,6 +313,7 @@ export const NewComposition: React.FC<{initialCompType: CompType}> = ({name="height"step={2}min={2}+ max={100000000}onValueChange={onHeightDirectlyChanged}/>{compHeightErrMessage ? (diff --git a/packages/cli/src/editor/helpers/validate-new-comp-data.ts b/packages/cli/src/editor/helpers/validate-new-comp-data.tsindex 3fa469d69f..29e08e46f4 100644--- a/packages/cli/src/editor/helpers/validate-new-comp-data.ts+++ b/packages/cli/src/editor/helpers/validate-new-comp-data.ts@@ -33,3 +33,19 @@ export const validateCompositionDimension = (return null;};++export const validateCompositionDuration = (value: string): string | null => {+ if (Number(value) % 1 !== 0) {+ return `Duration must be an integer.`;+ }++ if (Number.isNaN(Number(value))) {+ return 'Invalid number.';+ }++ if (Number(value) === 0) {+ return 'Duration cannot be zero.';+ }++ return null;+};