Skip to content
Open
Show file tree
Hide file tree
Changes from 2 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
11 changes: 7 additions & 4 deletions packages/uui-input/lib/uui-input.element.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,10 +123,10 @@ export class UUIInputElement extends UUIFormControlMixin(
* @default
*/
@property({ attribute: 'maxlength-message' })
maxlengthMessage: string | ((max: number, current: number) => string) = (
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changing this from current to exceeded is a breaking change.
We must remember we are not the only ones using the UI Library. So there may be someone who already uses this and parses in those values. So we need to have the logiv locally.
I would suggest to resolve in this way: Maximum ${max} characters, ${current-max} too many

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I didn't think of it. I updated this issue

maxlengthMessage: string | ((max: number, exceeded: number) => string) = (
max,
current,
) => `Maximum length exceeded (${current}/${max} characters)`;
exceeded,
) => `Maximum ${max} characters, ${exceeded} too many.`;

/**
* Specifies the interval between legal numbers of the input
Expand Down Expand Up @@ -256,7 +256,10 @@ export class UUIInputElement extends UUIFormControlMixin(
() => {
const label = this.maxlengthMessage;
if (typeof label === 'function') {
return label(this.maxlength ?? 0, String(this.value).length);
const max = this.maxlength ?? 0;
const currentLength = String(this.value).length;
const exceeded = currentLength - max;
return label(max, exceeded);
}
return label;
},
Expand Down
11 changes: 7 additions & 4 deletions packages/uui-textarea/lib/uui-textarea.element.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,10 +102,10 @@ export class UUITextareaElement extends UUIFormControlMixin(LitElement, '') {
* @default
*/
@property({ attribute: 'maxlength-message' })
maxlengthMessage: string | ((max: number, current: number) => string) = (
maxlengthMessage: string | ((max: number, exceeded: number) => string) = (
max,
current,
) => `Maximum ${max} characters, ${current} too many.`;
exceeded,
) => `Maximum ${max} characters, ${exceeded} too many.`;

@query('#textarea')
protected _textarea!: HTMLInputElement;
Expand Down Expand Up @@ -180,7 +180,10 @@ export class UUITextareaElement extends UUIFormControlMixin(LitElement, '') {
() => {
const label = this.maxlengthMessage;
if (typeof label === 'function') {
return label(this.maxlength ?? 0, String(this.value).length);
const max = this.maxlength ?? 0;
const currentLength = String(this.value).length;
const exceeded = currentLength - max;
return label(max, exceeded);
}
return label;
},
Expand Down
Loading