fix topic card title character counter

This commit is contained in:
Devin Howard 2017-02-18 20:23:11 -08:00
parent cf7a8addd4
commit ea3ca086d4
2 changed files with 56 additions and 37 deletions

View file

@ -6,6 +6,11 @@
font-family: helvetica; font-family: helvetica;
color: #727272; color: #727272;
line-height: 11px; line-height: 11px;
display: none;
}
.riek-editing + .nameCounter {
display: block;
} }
.nameCounter.forMap { .nameCounter.forMap {

View file

@ -1,13 +1,20 @@
import React from 'react' import React, { Component, PropTypes } from 'react'
import { RIETextArea } from 'riek' import { RIETextArea } from 'riek'
const Title = (props) => { class Title extends Component {
if (props.authorizedToEdit) { nameCounterText() {
// for some reason, there's an error if this isn't inside a function
return `${this.props.name.length}/140`
}
render() {
if (this.props.authorizedToEdit) {
return ( return (
<span className="title"> <span className="title">
<RIETextArea value={props.name} <RIETextArea value={this.props.name}
ref={textarea => { this.textarea = textarea }}
propName="name" propName="name"
change={props.onChange} change={this.props.onChange}
className="titleWrapper" className="titleWrapper"
id="titleActivator" id="titleActivator"
classEditing="riek-editing" classEditing="riek-editing"
@ -16,30 +23,37 @@ const Title = (props) => {
const ENTER = 13 const ENTER = 13
if (e.which === ENTER) { if (e.which === ENTER) {
e.preventDefault() e.preventDefault()
props.onChange({ name: e.target.value }) this.props.onChange({ name: e.target.value })
} }
},
onChange: e => {
if (!this.nameCounter) return
this.nameCounter.innerHTML = `${e.target.value.length}/140`
} }
}} }}
/> />
<span className="nameCounter" ref={span => { this.nameCounter = span }}>
{this.nameCounterText()}
</span>
</span> </span>
) )
} else { } else {
return ( return (
<span className="title"> <span className="title">
<span className="titleWrapper"> <span className="titleWrapper">
{props.name} {this.props.name}
</span> </span>
</span> </span>
) )
} }
} }
}
/*
* Title.propTypes = { Title.propTypes = {
* name: PropTypes.string, name: PropTypes.string,
* onChange: PropTypes.func, onChange: PropTypes.func,
* authorizedToEdit: PropTypes.bool authorizedToEdit: PropTypes.bool
* } }
*/
export default Title export default Title