Skip to content

Commit 664d68e

Browse files
authored
Decimal umb-property-editor-ui-number fixes (#18233)
* Numeric: renamed `#parseInt` function to `#parseNumber` * Numeric: Changed to use `@change` event * Number input: `max="Infinity"` was invalid markup We don't need to always set the `min` and `max` attributes. Leave the browser to do its thing. * Decimal: adds input `step` config
1 parent 67a66cb commit 664d68e

File tree

3 files changed

+18
-15
lines changed

3 files changed

+18
-15
lines changed

src/Umbraco.Web.UI.Client/src/packages/property-editors/number/Umbraco.Decimal.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,24 +12,24 @@ export const manifests: Array<UmbExtensionManifest> = [
1212
label: 'Minimum',
1313
description: 'Enter the minimum amount of number to be entered',
1414
propertyEditorUiAlias: 'Umb.PropertyEditorUi.Decimal',
15+
config: [{ alias: 'step', value: '0.001' }],
1516
},
1617
{
1718
alias: 'max',
1819
label: 'Maximum',
1920
description: 'Enter the maximum amount of number to be entered',
2021
propertyEditorUiAlias: 'Umb.PropertyEditorUi.Decimal',
22+
config: [
23+
{ alias: 'placeholder', value: '∞' },
24+
{ alias: 'step', value: '0.001' },
25+
],
2126
},
2227
{
2328
alias: 'step',
2429
label: 'Step size',
2530
description: 'Enter the intervals amount between each step of number to be entered',
2631
propertyEditorUiAlias: 'Umb.PropertyEditorUi.Decimal',
27-
config: [
28-
{
29-
alias: 'step',
30-
value: '0.01',
31-
},
32-
],
32+
config: [{ alias: 'step', value: '0.001' }],
3333
},
3434
],
3535
},

src/Umbraco.Web.UI.Client/src/packages/property-editors/number/Umbraco.Integer.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ export const manifests: Array<UmbExtensionManifest> = [
1818
label: 'Maximum',
1919
description: 'Enter the maximum amount of number to be entered',
2020
propertyEditorUiAlias: 'Umb.PropertyEditorUi.Integer',
21+
config: [{ alias: 'placeholder', value: '∞' }],
2122
},
2223
{
2324
alias: 'step',

src/Umbraco.Web.UI.Client/src/packages/property-editors/number/property-editor-ui-number.element.ts

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,9 @@ export class UmbPropertyEditorUINumberElement
3939

4040
public set config(config: UmbPropertyEditorConfigCollection | undefined) {
4141
if (!config) return;
42-
this._min = this.#parseInt(config.getValueByAlias('min')) || 0;
43-
this._max = this.#parseInt(config.getValueByAlias('max')) || Infinity;
44-
this._step = this.#parseInt(config.getValueByAlias('step'));
42+
this._min = this.#parseNumber(config.getValueByAlias('min'));
43+
this._max = this.#parseNumber(config.getValueByAlias('max'));
44+
this._step = this.#parseNumber(config.getValueByAlias('step'));
4545
this._placeholder = config.getValueByAlias('placeholder');
4646
}
4747

@@ -80,13 +80,15 @@ export class UmbPropertyEditorUINumberElement
8080
}
8181
}
8282

83-
#parseInt(input: unknown): number | undefined {
83+
#parseNumber(input: unknown): number | undefined {
8484
const num = Number(input);
85-
return Number.isNaN(num) ? undefined : num;
85+
return Number.isFinite(num) ? num : undefined;
8686
}
8787

88-
#onInput(e: InputEvent & { target: HTMLInputElement }) {
89-
this.value = this.#parseInt(e.target.value);
88+
#onChange(event: InputEvent & { target: HTMLInputElement }) {
89+
const newValue = event.target.value === '' ? undefined : this.#parseNumber(event.target.value);
90+
if (newValue === this.value) return;
91+
this.value = newValue;
9092
this.dispatchEvent(new UmbPropertyValueChangeEvent());
9193
}
9294

@@ -99,8 +101,8 @@ export class UmbPropertyEditorUINumberElement
99101
max=${ifDefined(this._max)}
100102
step=${ifDefined(this._step)}
101103
placeholder=${ifDefined(this._placeholder)}
102-
value=${this.value?.toString() ?? (this._placeholder ? '' : '0')}
103-
@input=${this.#onInput}
104+
value=${this.value?.toString() ?? ''}
105+
@change=${this.#onChange}
104106
?readonly=${this.readonly}>
105107
</uui-input>
106108
`;

0 commit comments

Comments
 (0)