diff --git a/packages/frontend/@n8n/design-system/src/directives/n8n-smart-decimal.test.ts b/packages/frontend/@n8n/design-system/src/directives/n8n-smart-decimal.test.ts index 2071ddcf2b..62660e9d32 100644 --- a/packages/frontend/@n8n/design-system/src/directives/n8n-smart-decimal.test.ts +++ b/packages/frontend/@n8n/design-system/src/directives/n8n-smart-decimal.test.ts @@ -11,7 +11,7 @@ describe('Directive n8n-truncate', () => { type: String, }, }, - template: '
{{text}}
', + template: '', }, { props: { @@ -35,7 +35,7 @@ describe('Directive n8n-truncate', () => { type: String, }, }, - template: '{{text}}
', + template: '', }, { props: { @@ -59,7 +59,7 @@ describe('Directive n8n-truncate', () => { type: String, }, }, - template: '{{text}}
', + template: '', }, { props: { @@ -83,7 +83,7 @@ describe('Directive n8n-truncate', () => { type: String, }, }, - template: '{{text}}
', + template: '', }, { props: { @@ -107,7 +107,7 @@ describe('Directive n8n-truncate', () => { type: String, }, }, - template: '
{{text}}
', + template: '', }, { props: { @@ -131,7 +131,7 @@ describe('Directive n8n-truncate', () => { type: String, }, }, - template: '
{{text}}
', + template: '', }, { props: { @@ -155,7 +155,7 @@ describe('Directive n8n-truncate', () => { type: String, }, }, - template: '{{text}}
', + template: '', }, { props: { @@ -179,7 +179,7 @@ describe('Directive n8n-truncate', () => { type: String, }, }, - template: '{{text}}
', + template: '', }, { props: { @@ -203,7 +203,7 @@ describe('Directive n8n-truncate', () => { type: String, }, }, - template: '{{text}}
', + template: '', }, { props: { @@ -227,7 +227,7 @@ describe('Directive n8n-truncate', () => { type: String, }, }, - template: '{{text}}
', + template: '', }, { props: { @@ -242,4 +242,32 @@ describe('Directive n8n-truncate', () => { ); expect(html()).toBe('42.12
'); }); + + it('rendered html should update when the value changes', async () => { + const { html, rerender } = render( + { + props: { + text: { + type: String, + }, + }, + template: '', + }, + { + props: { + text: '42.12', + }, + global: { + directives: { + n8nSmartDecimal, + }, + }, + }, + ); + expect(html()).toBe('42.12
'); + + await rerender({ text: '12.42' }); + + expect(html()).toBe('12.42
'); + }); }); diff --git a/packages/frontend/@n8n/design-system/src/directives/n8n-smart-decimal.ts b/packages/frontend/@n8n/design-system/src/directives/n8n-smart-decimal.ts index 13f4e72b89..93d33de77a 100644 --- a/packages/frontend/@n8n/design-system/src/directives/n8n-smart-decimal.ts +++ b/packages/frontend/@n8n/design-system/src/directives/n8n-smart-decimal.ts @@ -8,12 +8,12 @@ import type { DirectiveBinding, FunctionDirective } from 'vue'; * In your Vue template, use the directive `v-n8n-smart-decimal` passing the number and optionally the decimal places. * * Example: - *42.567
+ * * * Compiles to:42.57
* * Example with specified decimal places: - *42.56789
+ * * * Compiles to:42.5679
* @@ -28,7 +28,7 @@ export const n8nSmartDecimal: FunctionDirective = ( el: HTMLElement, binding: DirectiveBindingSome long text that will be truncated
+ * * * This will truncate the text content of the paragraph to 10 characters. * @@ -16,11 +16,11 @@ import type { DirectiveBinding, ObjectDirective } from 'vue'; * https://vuejs.org/guide/reusability/custom-directives#usage-on-components */ -export const n8nTruncate: ObjectDirective = { - mounted(el: HTMLElement, binding: DirectiveBinding) { - el.textContent = truncate(el.textContent ?? '', Number(binding.arg) || undefined); - }, - updated(el: HTMLElement, binding: DirectiveBinding) { - el.textContent = truncate(el.textContent ?? '', Number(binding.arg) || undefined); - }, +export const n8nTruncate: FunctionDirective