mirror of
https://github.com/flarum/framework.git
synced 2025-01-19 07:42:48 +08:00
fix: composer no longer autofocusing (#4149)
This commit is contained in:
parent
87fa4a32dd
commit
3294941226
|
@ -21,6 +21,7 @@ import LoadingIndicator from './LoadingIndicator';
|
|||
* - `placeholder`
|
||||
* - `disabled`
|
||||
* - `preview`
|
||||
* - `onTextEditorBuilt`
|
||||
*/
|
||||
export default class TextEditor extends Component {
|
||||
oninit(vnode) {
|
||||
|
@ -78,6 +79,7 @@ export default class TextEditor extends Component {
|
|||
|
||||
onbuild() {
|
||||
this.attrs.composer.editor = this.buildEditor(this.$('.TextEditor-editorContainer')[0]);
|
||||
this.attrs.onTextEditorBuilt?.();
|
||||
}
|
||||
|
||||
onupdate(vnode) {
|
||||
|
|
|
@ -31,6 +31,8 @@ export default class Composer extends Component {
|
|||
|
||||
// Store the initial position so that we can trigger animations correctly.
|
||||
this.prevPosition = this.state.position;
|
||||
|
||||
this.textEditorBuilt = false;
|
||||
}
|
||||
|
||||
view() {
|
||||
|
@ -53,7 +55,9 @@ export default class Composer extends Component {
|
|||
<div className="Composer-handle" oncreate={this.configHandle.bind(this)} />
|
||||
<ul className="Composer-controls">{listItems(this.controlItems().toArray())}</ul>
|
||||
<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>
|
||||
);
|
||||
|
@ -62,6 +66,17 @@ export default class Composer extends Component {
|
|||
onupdate(vnode) {
|
||||
super.onupdate(vnode);
|
||||
|
||||
if (this.textEditorBuilt) {
|
||||
this.updateContainer();
|
||||
}
|
||||
}
|
||||
|
||||
onTextEditorBuilt() {
|
||||
this.updateContainer();
|
||||
this.textEditorBuilt = true;
|
||||
}
|
||||
|
||||
updateContainer() {
|
||||
if (this.state.position === this.prevPosition) {
|
||||
// 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.
|
||||
|
|
|
@ -17,6 +17,7 @@ export interface IComposerBodyAttrs extends ComponentAttrs {
|
|||
user: any;
|
||||
confirmExit: string;
|
||||
disabled: boolean;
|
||||
onTextEditorBuilt?: Function | null;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -63,6 +64,7 @@ export default abstract class ComposerBody<CustomAttrs extends IComposerBodyAttr
|
|||
onchange={this.composer.fields!.content}
|
||||
onsubmit={this.onsubmit.bind(this)}
|
||||
value={this.composer.fields!.content()}
|
||||
onTextEditorBuilt={this.attrs.onTextEditorBuilt}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
@ -15,6 +15,8 @@ import Stream from '../../common/utils/Stream';
|
|||
* - `titlePlaceholder`
|
||||
*/
|
||||
export default class DiscussionComposer extends ComposerBody {
|
||||
static focusOnSelector = () => '.DiscussionComposer-title';
|
||||
|
||||
static initAttrs(attrs) {
|
||||
super.initAttrs(attrs);
|
||||
|
||||
|
@ -47,7 +49,7 @@ export default class DiscussionComposer extends ComposerBody {
|
|||
'discussionTitle',
|
||||
<h3>
|
||||
<input
|
||||
className="FormControl"
|
||||
className="FormControl DiscussionComposer-title"
|
||||
bidi={this.title}
|
||||
placeholder={this.attrs.titlePlaceholder}
|
||||
disabled={!!this.attrs.disabled}
|
||||
|
|
Loading…
Reference in New Issue
Block a user