Is wanting a div to be focus-able a good use case for contentEditable?
Personne n'a encore pris cette issue.
- Langage dominant
- JavaScript
- Étoiles
- 11.8k
- Forks
- 7.9k
- Merge moyen
- 1 j 11 h
- PR mergées (30 j)
- 11
Description
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.
Guide de contribution
Ouvrir le guide de contribution
Par où commencer
- Lisez l'issue en entier, puis le guide de contribution du projet.
- Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
- Forkez le dépôt et travaillez sur une branche.
- Ouvrez une pull request qui référence le numéro de l'issue.
Piste de recherche
Commencez par la section suppressContentEditableWarning de la documentation React DOM elements liée dans l’issue et examinez la formulation proposée au regard du cas d’utilisation décrit concernant le focus et l’ordre de tabulation. Confirmez les recommandations de la documentation et mettez à jour cette section si nécessaire ; le travail est terminé lorsqu’elle explique correctement le cas d’utilisation pris en charge et la restriction associée.
Rédigé par le modèle d'indexation à partir du texte de l'issue.
Évaluation
- Stack technique
- javascript, react
- Domaine
- documentation
- Type d'issue
- Documentation
- Difficulté
- 2/5
- Temps estimé
- 1-3 heures
- Activité
- À l'abandon
- Clarté
- Plutôt claire
- Accessibilité débutants
- 35/100