Skip to content

Commit

Permalink
fix: composer no longer autofocusing (#4149)
Browse files Browse the repository at this point in the history
  • Loading branch information
SychO9 authored Jan 3, 2025
1 parent 87fa4a3 commit 3294941
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 2 deletions.
2 changes: 2 additions & 0 deletions framework/core/js/src/common/components/TextEditor.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import LoadingIndicator from './LoadingIndicator';
* - `placeholder`
* - `disabled`
* - `preview`
* - `onTextEditorBuilt`
*/
export default class TextEditor extends Component {
oninit(vnode) {
Expand Down Expand Up @@ -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) {
Expand Down
17 changes: 16 additions & 1 deletion framework/core/js/src/forum/components/Composer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -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>
);
Expand All @@ -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.
Expand Down
2 changes: 2 additions & 0 deletions framework/core/js/src/forum/components/ComposerBody.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export interface IComposerBodyAttrs extends ComponentAttrs {
user: any;
confirmExit: string;
disabled: boolean;
onTextEditorBuilt?: Function | null;
}

/**
Expand Down Expand Up @@ -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>
Expand Down
4 changes: 3 additions & 1 deletion framework/core/js/src/forum/components/DiscussionComposer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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}
Expand Down

0 comments on commit 3294941

Please sign in to comment.