diff --git a/scm-ui-components/packages/ui-components/src/forms/Textarea.js b/scm-ui-components/packages/ui-components/src/forms/Textarea.js index 3db590122a..4ea3741a31 100644 --- a/scm-ui-components/packages/ui-components/src/forms/Textarea.js +++ b/scm-ui-components/packages/ui-components/src/forms/Textarea.js @@ -12,6 +12,7 @@ type Props = { label?: string, placeholder?: SelectItem[], value?: string, + autofocus?: boolean, onChange: (value: string, name?: string) => void, helpText?: string }; @@ -19,6 +20,12 @@ type Props = { class Textarea extends React.Component { field: ?HTMLTextAreaElement; + componentDidMount() { + if (this.props.autofocus && this.field) { + this.field.focus(); + } + } + handleInput = (event: SyntheticInputEvent) => { this.props.onChange(event.target.value, this.props.name); }; diff --git a/scm-ui-components/packages/ui-components/src/repos/DiffFile.js b/scm-ui-components/packages/ui-components/src/repos/DiffFile.js index 24aa407fb0..ccc07f2ea1 100644 --- a/scm-ui-components/packages/ui-components/src/repos/DiffFile.js +++ b/scm-ui-components/packages/ui-components/src/repos/DiffFile.js @@ -56,6 +56,12 @@ class DiffFile extends React.Component { })); }; + setCollapse = (collapsed: boolean) => { + this.setState({ + collapsed + }); + }; + createHunkHeader = (hunk: Hunk, i: number) => { const { classes } = this.props; if (i > 0) { @@ -166,7 +172,7 @@ class DiffFile extends React.Component { ); } - const fileControls = fileControlFactory ? fileControlFactory(file) : null; + const fileControls = fileControlFactory ? fileControlFactory(file, this.setCollapse) : null; return (
diff --git a/scm-ui-components/packages/ui-components/src/repos/DiffTypes.js b/scm-ui-components/packages/ui-components/src/repos/DiffTypes.js index f841de6e08..74803e0a4e 100644 --- a/scm-ui-components/packages/ui-components/src/repos/DiffTypes.js +++ b/scm-ui-components/packages/ui-components/src/repos/DiffTypes.js @@ -58,7 +58,7 @@ export type DiffEventContext = BaseContext & { export type DiffEventHandler = (context: DiffEventContext) => void; -export type FileControlFactory = (file: File) => ?React.Node; +export type FileControlFactory = (file: File, setCollapseState: (boolean) => void) => ?React.Node; export type DiffObjectProps = { sideBySide: boolean,