Skip to content
This repository has been archived by the owner on Jan 6, 2022. It is now read-only.

fixed: focussing on title-edit #602

Merged
merged 1 commit into from
Nov 22, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 22 additions & 17 deletions app/components/title-field.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import React, { Component } from 'react'
import ReactDOM from 'react-dom'
import styled from 'styled-components'
import Icon from './icon'
import { Plain as PlainButton, Green as GreenButton } from './button'
Expand Down Expand Up @@ -35,32 +36,38 @@ const EditableFieldWrapper = styled.div`
}
`

const InputField = styled.input`
const InputFieldStyle = styled.input`
:focus {
outline: none;
}
`

class InputField extends Component {
componentDidMount () {
const input = ReactDOM.findDOMNode(this)
input.focus()
input.select()
}
render () {
return <InputFieldStyle {...this.props} />
}
}

class TitleField extends Component {
startEditing () {
this.setState({ editing: true })
constructor (props) {
super(props)
this.titleInput = React.createRef()
}

onclick (ev) {
ev.stopPropagation()
ev.preventDefault()
this.startEditing()

// setTimeout? Because ref on input is set asynchronously, and later. So we can't do focus, select on it until ref is set
setTimeout(() => {
this.titleInput.focus()
this.titleInput.select()
}, 0)
this.setState({ editing: true })
}

commit () {
const oldValue = this.props.value
const newValue = this.titleInput.value
const newValue = ReactDOM.findDOMNode(this.titleInput.current).value
if (oldValue !== newValue) {
this.props.onChange(newValue)
}
Expand Down Expand Up @@ -108,14 +115,12 @@ class TitleField extends Component {
className='bn f6 pl1 normal w-100'
defaultValue={value}
onKeyUp={ev => this.handleKeyup(ev)}
innerRef={input => {
this.titleInput = input
}}
ref={this.titleInput}
/>
{!modified ? (
<PlainButton onClick={() => this.commit()}>Save</PlainButton>
) : (
{modified ? (
<GreenButton onClick={() => this.commit()}>Save</GreenButton>
) : (
<PlainButton onClick={() => this.cancel()}>Save</PlainButton>
)}
</EditableFieldWrapper>
</div>
Expand Down
12 changes: 8 additions & 4 deletions app/containers/drag-drop.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,14 @@ const DropIcon = styled(Icon)`
color: white;
`

const DragDropContainer = connect(mapStateToProps, mapDispatchToProps)(function(props){
return <DropFrame {...props}>
<DropIcon name='create-new-dat' />
</DropFrame>
const DragDropContainer = connect(mapStateToProps, mapDispatchToProps)(function (
props
) {
return (
<DropFrame {...props}>
<DropIcon name='create-new-dat' />
</DropFrame>
)
})

export default DragDropContainer