diff --git a/packages/blocks/src/root-block/widgets/ai-panel/ai-panel.ts b/packages/blocks/src/root-block/widgets/ai-panel/ai-panel.ts index fc594e0fdc24..2abe55b480d1 100644 --- a/packages/blocks/src/root-block/widgets/ai-panel/ai-panel.ts +++ b/packages/blocks/src/root-block/widgets/ai-panel/ai-panel.ts @@ -350,6 +350,10 @@ export class AffineAIPanelWidget extends WidgetComponent { .then(({ x, y }) => { this.style.left = `${x}px`; this.style.top = `${y}px`; + setTimeout(() => { + const input = this.shadowRoot?.querySelector('ai-panel-input'); + input?.textarea?.focus(); + }, 0); }) .catch(console.error); }); diff --git a/packages/blocks/src/root-block/widgets/ai-panel/components/state/input.ts b/packages/blocks/src/root-block/widgets/ai-panel/components/state/input.ts index 87547e24e0c9..0e57647890e9 100644 --- a/packages/blocks/src/root-block/widgets/ai-panel/components/state/input.ts +++ b/packages/blocks/src/root-block/widgets/ai-panel/components/state/input.ts @@ -85,11 +85,11 @@ export class AIPanelInput extends WithDisposable(LitElement) { `; private _onInput = () => { - this._textarea.style.height = 'auto'; - this._textarea.style.height = this._textarea.scrollHeight + 'px'; + this.textarea.style.height = 'auto'; + this.textarea.style.height = this.textarea.scrollHeight + 'px'; - this.onInput?.(this._textarea.value); - const value = this._textarea.value.trim(); + this.onInput?.(this.textarea.value); + const value = this.textarea.value.trim(); if (value.length > 0) { this._arrow.dataset.active = ''; this._hasContent = true; @@ -107,7 +107,7 @@ export class AIPanelInput extends WithDisposable(LitElement) { }; private _sendToAI = () => { - const value = this._textarea.value.trim(); + const value = this.textarea.value.trim(); if (value.length === 0) return; this.onFinish?.(value); @@ -115,12 +115,6 @@ export class AIPanelInput extends WithDisposable(LitElement) { }; override render() { - this.updateComplete - .then(() => { - this._textarea.focus(); - }) - .catch(console.error); - return html`