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