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

Commit

Permalink
Merge pull request #602 from dat-land/fix/can-be-title-chenging
Browse files Browse the repository at this point in the history
fixed: focussing on title-edit
  • Loading branch information
AtuyL authored Nov 22, 2018
2 parents 2957ffc + be93e2b commit aaafee7
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 21 deletions.
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

0 comments on commit aaafee7

Please sign in to comment.