mirror of
https://github.com/flarum/core.git
synced 2025-08-09 01:46:35 +02:00
fix: composer no longer autofocusing (#4149)
This commit is contained in:
@@ -21,6 +21,7 @@ import LoadingIndicator from './LoadingIndicator';
|
|||||||
* - `placeholder`
|
* - `placeholder`
|
||||||
* - `disabled`
|
* - `disabled`
|
||||||
* - `preview`
|
* - `preview`
|
||||||
|
* - `onTextEditorBuilt`
|
||||||
*/
|
*/
|
||||||
export default class TextEditor extends Component {
|
export default class TextEditor extends Component {
|
||||||
oninit(vnode) {
|
oninit(vnode) {
|
||||||
@@ -78,6 +79,7 @@ export default class TextEditor extends Component {
|
|||||||
|
|
||||||
onbuild() {
|
onbuild() {
|
||||||
this.attrs.composer.editor = this.buildEditor(this.$('.TextEditor-editorContainer')[0]);
|
this.attrs.composer.editor = this.buildEditor(this.$('.TextEditor-editorContainer')[0]);
|
||||||
|
this.attrs.onTextEditorBuilt?.();
|
||||||
}
|
}
|
||||||
|
|
||||||
onupdate(vnode) {
|
onupdate(vnode) {
|
||||||
|
@@ -31,6 +31,8 @@ export default class Composer extends Component {
|
|||||||
|
|
||||||
// Store the initial position so that we can trigger animations correctly.
|
// Store the initial position so that we can trigger animations correctly.
|
||||||
this.prevPosition = this.state.position;
|
this.prevPosition = this.state.position;
|
||||||
|
|
||||||
|
this.textEditorBuilt = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
view() {
|
view() {
|
||||||
@@ -53,7 +55,9 @@ export default class Composer extends Component {
|
|||||||
<div className="Composer-handle" oncreate={this.configHandle.bind(this)} />
|
<div className="Composer-handle" oncreate={this.configHandle.bind(this)} />
|
||||||
<ul className="Composer-controls">{listItems(this.controlItems().toArray())}</ul>
|
<ul className="Composer-controls">{listItems(this.controlItems().toArray())}</ul>
|
||||||
<div className="Composer-content" onclick={showIfMinimized}>
|
<div className="Composer-content" onclick={showIfMinimized}>
|
||||||
{ComposerBody && <ComposerBody {...body.attrs} composer={this.state} disabled={classes.minimized} />}
|
{ComposerBody && (
|
||||||
|
<ComposerBody {...body.attrs} composer={this.state} disabled={classes.minimized} onTextEditorBuilt={this.onTextEditorBuilt.bind(this)} />
|
||||||
|
)}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
@@ -62,6 +66,17 @@ export default class Composer extends Component {
|
|||||||
onupdate(vnode) {
|
onupdate(vnode) {
|
||||||
super.onupdate(vnode);
|
super.onupdate(vnode);
|
||||||
|
|
||||||
|
if (this.textEditorBuilt) {
|
||||||
|
this.updateContainer();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
onTextEditorBuilt() {
|
||||||
|
this.updateContainer();
|
||||||
|
this.textEditorBuilt = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
updateContainer() {
|
||||||
if (this.state.position === this.prevPosition) {
|
if (this.state.position === this.prevPosition) {
|
||||||
// Set the height of the Composer element and its contents on each redraw,
|
// Set the height of the Composer element and its contents on each redraw,
|
||||||
// so that they do not lose it if their DOM elements are recreated.
|
// so that they do not lose it if their DOM elements are recreated.
|
||||||
|
@@ -17,6 +17,7 @@ export interface IComposerBodyAttrs extends ComponentAttrs {
|
|||||||
user: any;
|
user: any;
|
||||||
confirmExit: string;
|
confirmExit: string;
|
||||||
disabled: boolean;
|
disabled: boolean;
|
||||||
|
onTextEditorBuilt?: Function | null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -63,6 +64,7 @@ export default abstract class ComposerBody<CustomAttrs extends IComposerBodyAttr
|
|||||||
onchange={this.composer.fields!.content}
|
onchange={this.composer.fields!.content}
|
||||||
onsubmit={this.onsubmit.bind(this)}
|
onsubmit={this.onsubmit.bind(this)}
|
||||||
value={this.composer.fields!.content()}
|
value={this.composer.fields!.content()}
|
||||||
|
onTextEditorBuilt={this.attrs.onTextEditorBuilt}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
@@ -15,6 +15,8 @@ import Stream from '../../common/utils/Stream';
|
|||||||
* - `titlePlaceholder`
|
* - `titlePlaceholder`
|
||||||
*/
|
*/
|
||||||
export default class DiscussionComposer extends ComposerBody {
|
export default class DiscussionComposer extends ComposerBody {
|
||||||
|
static focusOnSelector = () => '.DiscussionComposer-title';
|
||||||
|
|
||||||
static initAttrs(attrs) {
|
static initAttrs(attrs) {
|
||||||
super.initAttrs(attrs);
|
super.initAttrs(attrs);
|
||||||
|
|
||||||
@@ -47,7 +49,7 @@ export default class DiscussionComposer extends ComposerBody {
|
|||||||
'discussionTitle',
|
'discussionTitle',
|
||||||
<h3>
|
<h3>
|
||||||
<input
|
<input
|
||||||
className="FormControl"
|
className="FormControl DiscussionComposer-title"
|
||||||
bidi={this.title}
|
bidi={this.title}
|
||||||
placeholder={this.attrs.titlePlaceholder}
|
placeholder={this.attrs.titlePlaceholder}
|
||||||
disabled={!!this.attrs.disabled}
|
disabled={!!this.attrs.disabled}
|
||||||
|
Reference in New Issue
Block a user