Skip to content

Commit 5c08c1a

Browse files
authored
Merge pull request #1813 from umbraco/feature/image-cropper-config-improvements
Image cropper config improvements
2 parents 0dbf2ff + 2a459b4 commit 5c08c1a

File tree

1 file changed

+34
-2
lines changed

1 file changed

+34
-2
lines changed

src/packages/media/media/property-editors/image-crops-configuration/property-editor-ui-image-crops-configuration.element.ts

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
import { html, customElement, property, css, repeat, state } from '@umbraco-cms/backoffice/external/lit';
1+
import { html, customElement, property, css, repeat, state, query } from '@umbraco-cms/backoffice/external/lit';
22
import { UmbTextStyles } from '@umbraco-cms/backoffice/style';
33
import type { UmbPropertyEditorUiElement } from '@umbraco-cms/backoffice/extension-registry';
44
import { UmbLitElement } from '@umbraco-cms/backoffice/lit-element';
55
import { UmbPropertyValueChangeEvent } from '@umbraco-cms/backoffice/property-editor';
6+
import { generateAlias } from '@umbraco-cms/backoffice/utils';
67

78
export type UmbCrop = {
89
label: string;
@@ -19,13 +20,18 @@ export class UmbPropertyEditorUIImageCropsConfigurationElement
1920
extends UmbLitElement
2021
implements UmbPropertyEditorUiElement
2122
{
23+
@query('#label')
24+
private _labelInput!: HTMLInputElement;
25+
2226
//TODO MAKE TYPE
2327
@property({ attribute: false })
2428
value: UmbCrop[] = [];
2529

2630
@state()
2731
editCropAlias = '';
2832

33+
#oldInputValue = '';
34+
2935
#onRemove(alias: string) {
3036
this.value = [...this.value.filter((item) => item.alias !== alias)];
3137
this.dispatchEvent(new UmbPropertyValueChangeEvent());
@@ -92,6 +98,7 @@ export class UmbPropertyEditorUIImageCropsConfigurationElement
9298
this.dispatchEvent(new UmbPropertyValueChangeEvent());
9399

94100
form.reset();
101+
this._labelInput.focus();
95102
}
96103

97104
#renderActions() {
@@ -101,6 +108,24 @@ export class UmbPropertyEditorUIImageCropsConfigurationElement
101108
: html`<uui-button look="secondary" type="submit" label="Add"></uui-button>`;
102109
}
103110

111+
#onLabelInput() {
112+
const value = this._labelInput.value ?? '';
113+
114+
const aliasValue = generateAlias(value);
115+
116+
const alias = this.shadowRoot?.querySelector('#alias') as HTMLInputElement;
117+
118+
if (!alias) return;
119+
120+
const oldAliasValue = generateAlias(this.#oldInputValue);
121+
122+
if (alias.value === oldAliasValue || !alias.value) {
123+
alias.value = aliasValue;
124+
}
125+
126+
this.#oldInputValue = value;
127+
}
128+
104129
render() {
105130
if (!this.value) this.value = [];
106131

@@ -109,7 +134,14 @@ export class UmbPropertyEditorUIImageCropsConfigurationElement
109134
<form @submit=${this.#onSubmit}>
110135
<div class="input">
111136
<uui-label for="label">Label</uui-label>
112-
<uui-input label="Label" id="label" name="label" type="text" autocomplete="false" value=""></uui-input>
137+
<uui-input
138+
@input=${this.#onLabelInput}
139+
label="Label"
140+
id="label"
141+
name="label"
142+
type="text"
143+
autocomplete="false"
144+
value=""></uui-input>
113145
</div>
114146
<div class="input">
115147
<uui-label for="alias">Alias</uui-label>

0 commit comments

Comments
 (0)