Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ export const data: Array<UmbMockMediaTypeModel> = [
},
],
compositions: [],
isFolder: false,
isFolder: true,
hasChildren: false,
collection: {
id: '3a0156c4-3b8c-4803-bdc1-6871faa83fff',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {
property,
type PropertyValues,
} from '@umbraco-cms/backoffice/external/lit';
import type { UUIInputElement, UUIInputEvent } from '@umbraco-cms/backoffice/external/uui';
import type { UUIInputElement } from '@umbraco-cms/backoffice/external/uui';
import { UmbId } from '@umbraco-cms/backoffice/id';
import { UmbMediaTypeStructureRepository, type UmbAllowedMediaTypeModel } from '@umbraco-cms/backoffice/media-type';
import { UmbLitElement } from '@umbraco-cms/backoffice/lit-element';
Expand Down Expand Up @@ -150,13 +150,26 @@ export class UmbMediaPickerFolderPathElement extends UmbLitElement {

#cancelFolderTypeSelection() {
this._selectingFolderType = false;
this.#focusAddFolderButton();
}

async #addFolder(e: UUIInputEvent) {
e.stopPropagation();
#focusAddFolderButton() {
requestAnimationFrame(() => {
this.getHostElement().shadowRoot!.querySelector<HTMLElement>('#add-folder')?.focus();
});
}

#onSubmit(e: SubmitEvent) {
e.preventDefault();
const folderName = new FormData(e.target as HTMLFormElement).get('folderName');
this.#addFolder(typeof folderName === 'string' ? folderName : undefined);
}

async #addFolder(newName?: string) {
if (!this._typingNewFolder) return;

const newName = e.target.value as string;
this._typingNewFolder = false;
this.#focusAddFolderButton();
if (!newName || !this.#selectedFolderType?.unique) return;

const newUnique = UmbId.new();
Expand Down Expand Up @@ -196,12 +209,17 @@ export class UmbMediaPickerFolderPathElement extends UmbLitElement {
this.dispatchEvent(new UmbChangeEvent());
}

#onKeypress(e: KeyboardEvent) {
if (e.key === 'Enter') {
requestAnimationFrame(() => {
const element = this.getHostElement().shadowRoot!.querySelector('#new-folder') as UUIInputElement;
element.blur();
});
#cancelFolderCreation() {
this._typingNewFolder = false;
this._selectingFolderType = false;
this.#focusAddFolderButton();
}

#onKeydown(e: KeyboardEvent) {
if (e.key === 'Escape') {
e.preventDefault();
e.stopImmediatePropagation();
this.#cancelFolderCreation();
}
}

Expand All @@ -225,12 +243,28 @@ export class UmbMediaPickerFolderPathElement extends UmbLitElement {

#renderFolderCreation() {
if (this._typingNewFolder) {
return html`<uui-input
id="new-folder"
label=${this.localize.term('create_enterFolderName')}
placeholder=${this.localize.term('create_enterFolderName')}
@blur=${this.#addFolder}
@keypress=${this.#onKeypress}></uui-input>`;
return html`
<uui-form>
<form id="new-folder-form" novalidate @submit=${this.#onSubmit}>
<uui-input
id="new-folder"
name="folderName"
label=${this.localize.term('create_enterFolderName')}
placeholder=${this.localize.term('create_enterFolderName')}
@keydown=${this.#onKeydown}>
<uui-button
slot="append"
type="button"
compact
label=${this.localize.term('general_cancel')}
@click=${this.#cancelFolderCreation}>
<uui-icon name="remove"></uui-icon>
</uui-button>
</uui-input>
<uui-button look="outline" type="submit" label=${this.localize.term('actions_create')}></uui-button>
</form>
</uui-form>
`;
}

if (this._selectingFolderType) {
Expand All @@ -254,6 +288,7 @@ export class UmbMediaPickerFolderPathElement extends UmbLitElement {
}

return html`<uui-button
id="add-folder"
label=${this.localize.term('visuallyHiddenTexts_createNewFolder')}
compact
@click=${this.#onAddFolderClick}>
Expand All @@ -267,17 +302,21 @@ export class UmbMediaPickerFolderPathElement extends UmbLitElement {
display: flex;
align-items: center;
margin: 0 var(--uui-size-3);
overflow: hidden;
min-width: 0;
}

#new-folder {
#new-folder-form {
display: flex;
align-items: center;
gap: var(--uui-size-2);
margin-left: var(--uui-size-2);
width: 150px;
height: 100%;
flex-shrink: 0;
}

#new-folder {
width: 220px;
}

#folder-type-selection {
display: flex;
align-items: center;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -754,7 +754,6 @@ export class UmbMediaPickerModalElement extends UmbPickerModalBaseElement<
}

umb-media-picker-folder-path {
overflow: hidden;
min-width: 0;
flex: 1 1 0%;
}
Expand Down
Loading