Skip to content

Commit

Permalink
fix(react-tinacms-editor): seevral UX issues addressed for tables, he…
Browse files Browse the repository at this point in the history
…adings, and the link modal (#1393)
  • Loading branch information
jpuri committed Aug 12, 2020
1 parent a5ea2a6 commit 28cfaec
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 5 deletions.
Expand Up @@ -44,6 +44,7 @@ export const ProsemirrorMenu: FunctionComponent = () => {
<MenuButton
ref={menuButtonRef}
data-tooltip="Heading"
title="Heading"
onClick={toggle}
active={active}
>
Expand Down
Expand Up @@ -43,8 +43,11 @@ export class InnerForm extends React.Component<Props, State> {
// title: this.props.title || '',
}

inputRef = React.createRef<HTMLInputElement>()

componentDidMount() {
document.addEventListener('keydown', this.onEscapeCancel)
if (this.inputRef.current) this.inputRef.current.focus()
}

componentWillUnmount() {
Expand All @@ -56,6 +59,13 @@ export class InnerForm extends React.Component<Props, State> {
if (href !== prevProps.href) this.setState(() => ({ href }))
}

closeModal() {
const { href } = this.state
const { cancel, removeLink, href: originalHref } = this.props
if (!href && !originalHref) removeLink()
cancel()
}

setHref = ({ target: { value } }: E) => this.setState(() => ({ href: value }))
// setTitle = ({ target: { value } }: E) =>
// this.setState(() => ({ title: value }))
Expand All @@ -70,7 +80,7 @@ export class InnerForm extends React.Component<Props, State> {

onEscapeCancel = (e: KeyboardEvent) => {
if (e.keyCode === 27) {
this.props.cancel()
this.closeModal()
}
}

Expand All @@ -93,6 +103,7 @@ export class InnerForm extends React.Component<Props, State> {
/> */}
<LinkLabel>URL</LinkLabel>
<LinkInput
ref={this.inputRef}
placeholder="Enter URL"
type={'text'}
value={href}
Expand All @@ -101,7 +112,9 @@ export class InnerForm extends React.Component<Props, State> {
/>
<LinkActions>
<DeleteLink onClick={removeLink}>Delete</DeleteLink>
<SaveLink onClick={this.save}>Save</SaveLink>
<SaveLink onClick={this.save} disabled={!href}>
Save
</SaveLink>
</LinkActions>
</LinkPopup>
)
Expand Down Expand Up @@ -194,6 +207,10 @@ const SaveLink = styled.button`
&:active {
background-color: #0574e4;
}
&:disabled {
background-color: #d1d1d1;
box-shadow: none;
}
`

const DeleteLink = styled.button`
Expand Down
Expand Up @@ -58,8 +58,8 @@ export const insertTable = (
const newTable = table.createChecked(null, rows)
const { selection, tr } = state
const { $from, $to } = selection
dispatch(
tr.replaceWith($from.pos - 1, $to.pos + 1, newTable).scrollIntoView()
)
const start = $from.pos - 1
const end = $to.pos < state.doc.content.size ? $to.pos + 1 : $to.pos
dispatch(tr.replaceWith(start, end, newTable).scrollIntoView())
return true
}

0 comments on commit 28cfaec

Please sign in to comment.