Is wanting a div to be focus-able a good use case for contentEditable?
Chưa có ai nhận issue này.
- Ngôn ngữ chính
- JavaScript
- Star
- 11.8k
- Fork
- 7.9k
- Merge trung bình
- 1 ngày 11 giờ
- Pull request đã merge (30 ngày)
- 11
Mô tả
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.
Hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Hướng nghiên cứu
Bắt đầu với phần suppressContentEditableWarning trong tài liệu React DOM elements được liên kết trong issue và xem xét cách diễn đạt được đề xuất dựa trên trường hợp sử dụng về focus và thứ tự tab đã mô tả. Xác nhận hướng dẫn trong tài liệu và cập nhật phần đó nếu phù hợp; hoàn tất khi phần này giải thích chính xác trường hợp sử dụng được hỗ trợ và điểm hạn chế.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Đánh giá
- Công nghệ
- javascript, react
- Lĩnh vực
- documentation
- Loại issue
- Tài liệu
- Độ khó
- 2/5
- Thời gian dự kiến
- 1-3 giờ
- Mức độ hoạt động
- Đình trệ
- Độ rõ ràng
- Khá rõ ràng
- Mức phù hợp với người mới
- 35/100