Is wanting a div to be focus-able a good use case for contentEditable?
Nadie ha tomado este issue todavía.
- Lenguaje dominante
- JavaScript
- Estrellas
- 11.8k
- Forks
- 7.9k
- Merge medio
- 1 d 11 h
- PR fusionados (30 d)
- 11
Descripción
The documentation says
suppressContentEditableWarning
Normally, there is a warning when an element with children is also marked as contentEditable, because it won’t work. This attribute suppresses that warning. Don’t use this unless you are building a library like Draft.js that manages contentEditable manually.
Well I'm not building a library which manages contentEditable manually, but I think I have a situation that contentEditable makes sense for that - if yall agree - might be good to update the documentation for.
I am building a sort of inline-editable component which will toggle between "view" and "editable" versions of their rendered contents. So my render method looks like this
render = () => (
<EditableContainer className={classnames({ 'has-spinner inline': this.state.saving })}>
{this.state.editing ? (
this.props.renderEdit({
value: this.state.currentValue,
onChange: (currentValue) => this.setState({currentValue}),
onKeyDown: this.onKeyDown,
onBlur: this.save,
ref: this.editRef,
})
) : (
<div contentEditable suppressContentEditableWarning onFocus={this.transitionToEdit}>
{this.props.renderView({value: this.props.value})}
</div>
)}
</EditableContainer>
);
transitionToEdit = () => {
this.setState({editing: true, currentValue: this.props.value}, () => {
if(this.editRef.current)
this.editRef.current.focus();
});
}
Note that I wrap the "view" component in a contentEditable div, this is primarily so that it can obtain focus and is in the natural tab order. Once it is tabbed to, I actually no longer render it, instead switching directly to the "editable view". So I'm pretty sure the warning is moot since - nothing can actually happen within the contentEditable, it can trigger and...that's about all, however it is needed in order to properly allow focus without manually managing tabIndex.
Is this a valid use case? If so, I would recommend updating the documentation to say something like
Don’t use this unless you are building a library like Draft.js that manages contentEditable manually. You may also use it to allow focus to shift to otherwise unfocusable element but beware that actually using the contentEditable component might step you outside the bounds of what React can properly control.
Guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Línea de trabajo
Comienza con la sección suppressContentEditableWarning de la documentación de React DOM elements enlazada en el issue y revisa la redacción propuesta en relación con el caso de uso descrito de enfoque y orden de tabulación. Confirma las indicaciones de la documentación y actualiza esa sección si corresponde; se considerará terminado cuando explique con precisión el caso de uso compatible y la salvedad.
Escrito por el modelo de indexación a partir del texto del issue.
Evaluación
- Stack tecnológico
- javascript, react
- Área
- documentation
- Tipo de issue
- Documentación
- Dificultad
- 2/5
- Tiempo estimado
- 1-3 horas
- Estado de actividad
- Estancado
- Claridad
- Bastante claro
- Aptitud para principiantes
- 35/100