Is wanting a div to be focus-able a good use case for contentEditable?
还没有人认领这个 Issue。
- 主要语言
- JavaScript
- 星标
- 11.8k
- 派生
- 7.9k
- 平均合并
- 1 天 11 小时
- 30 天内合并 PR
- 11
描述
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.
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
调研方向
从 issue 中链接的 React DOM elements 文档里的 suppressContentEditableWarning 部分开始,根据所描述的 focus 和 tab 顺序使用场景审阅拟议的措辞。确认文档指导,并在适当时更新该部分;当其准确说明受支持的使用场景及注意事项时即可完成。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- javascript, react
- 领域
- documentation
- Issue 类型
- 文档
- 难度
- 2/5
- 预计耗时
- 1-3 小时
- 活跃度
- 停滞
- 描述清晰度
- 基本清楚
- 新手友好度
- 35/100