I'm trying to programmatically trigger a onCancel
event on Inline edit view component of Atlaskit, But I couldn't find any API docs where I can trigger on cancel event on this inline component.
import React from 'react';
import styled from 'styled-components';
import Textfield from '@atlaskit/textfield';
import { gridSize, fontSize } from '@atlaskit/theme';
import InlineEdit from '@atlaskit/inline-edit';
const ReadViewContainer = styled.div`
display: flex;
font-size: ${fontSize()}px;
line-height: ${(gridSize() * 2.5) / fontSize()};
max-width: 100%;
min-height: ${(gridSize() * 2.5) / fontSize()}em;
padding: ${gridSize()}px ${gridSize() - 2}px;
word-break: break-word;
`;
interface State {
editValue: string;
}
export default class InlineEditExample extends React.Component<void, State> {
state = {
editValue: 'Field value',
};
render() {
return (
<div
style={{
padding: `${gridSize()}px ${gridSize()}px ${gridSize() * 6}px`,
}}
>
<InlineEdit
defaultValue={this.state.editValue}
label="Inline edit"
editView={fieldProps => <Textfield {...fieldProps} autoFocus />}
readView={() => (
<ReadViewContainer>
{this.state.editValue || 'Click to enter value'}
</ReadViewContainer>
)}
onConfirm={value => this.setState({ editValue: value })}
/>
</div>
);
}
}
In my opinion the best way to do this is to use the InlineEditUncontrolled component and make it a controlled component using the following props: onConfirm, onCancel, isEditing. After that you can change internal isEditing state to false.