Skip to content

Commit

Permalink
template widget must handle focus (#146)
Browse files Browse the repository at this point in the history
fixed #145

Signed-off-by: Jonas Helming <jhelming@eclipsesource.com>
  • Loading branch information
JonasHelming committed Jul 21, 2022
1 parent fb1fbd4 commit 3d5ab33
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion templates/widget/widget.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { injectable, postConstruct, inject } from '@theia/core/shared/inversify'
import { AlertMessage } from '@theia/core/lib/browser/widgets/alert-message';
import { ReactWidget } from '@theia/core/lib/browser/widgets/react-widget';
import { MessageService } from '@theia/core';
import { Message } from '@theia/core/lib/browser';

@injectable()
export class <%= params.extensionPrefix %>Widget extends ReactWidget {
Expand All @@ -28,12 +29,20 @@ export class <%= params.extensionPrefix %>Widget extends ReactWidget {
in order to display an info message to end users.`;
return <div id='widget-container'>
<AlertMessage type='INFO' header={header} />
<button className='theia-button secondary' title='Display Message' onClick={_a => this.displayMessage()}>Display Message</button>
<button id='displayMessageButton' className='theia-button secondary' title='Display Message' onClick={_a => this.displayMessage()}>Display Message</button>
</div>
}

protected displayMessage(): void {
this.messageService.info('Congratulations: <%= params.extensionPrefix %> Widget Successfully Created!');
}

protected onActivateRequest(msg: Message): void {
super.onActivateRequest(msg);
const htmlElement = document.getElementById('displayMessageButton');
if (htmlElement) {
htmlElement.focus();
}
}

}

0 comments on commit 3d5ab33

Please sign in to comment.