focus and clear observers

This commit is contained in:
Niels Lyngsø
2023-06-07 19:06:44 +02:00
parent 0cb1d518f9
commit f0d8caa9cf
3 changed files with 14 additions and 3 deletions

View File

@@ -46,9 +46,18 @@ export class UmbDocumentTypeWorkspaceEditorElement extends UmbLitElement {
#observeDocumentType() {
if (!this.#workspaceContext) return;
this.observe(this.#workspaceContext.name, (name) => (this._name = name));
this.observe(this.#workspaceContext.alias, (alias) => (this._alias = alias));
this.observe(this.#workspaceContext.icon, (icon) => (this._icon = icon));
this.observe(this.#workspaceContext.name, (name) => (this._name = name), '_observeName');
this.observe(this.#workspaceContext.alias, (alias) => (this._alias = alias), '_observeAlias');
this.observe(this.#workspaceContext.icon, (icon) => (this._icon = icon), '_observeIcon');
this.observe(this.#workspaceContext.isNew, (isNew) => {
if(isNew) {
// TODO: Would be good with a more general way to bring focus to the name input.
(this.shadowRoot?.querySelector('#name') as HTMLElement)?.focus();
}
this.removeControllerByUnique('_observeIsNew');
}, '_observeIsNew');
}
// TODO. find a way where we don't have to do this for all workspaces.

View File

@@ -115,6 +115,7 @@ export class UmbDocumentTypeWorkspaceContext
}
async create(parentId: string | null) {
const { data } = await this.structure.createScaffold(parentId);
if (!data) return undefined;

View File

@@ -40,6 +40,7 @@ export class UmbDocumentTypeWorkspaceElement extends UmbLitElement {
path: 'edit/:id',
component: import('./document-type-workspace-editor.element.js'),
setup: (_component, info) => {
this.removeControllerByUnique('_observeIsNew');
const id = info.match.params.id;
this.#workspaceContext.load(id);
},