diff --git a/.changeset/fast-hornets-run.md b/.changeset/fast-hornets-run.md new file mode 100644 index 00000000000..8a8f88d8943 --- /dev/null +++ b/.changeset/fast-hornets-run.md @@ -0,0 +1,5 @@ +--- +'@talend/design-system': minor +--- + +Design System - InlineEdit and InlineEditMulti can now have a maxLength attribute diff --git a/packages/design-system/src/components/InlineEditing/Primitives/InlineEditingPrimitive.tsx b/packages/design-system/src/components/InlineEditing/Primitives/InlineEditingPrimitive.tsx index fd0bb640a14..72af8a0e640 100644 --- a/packages/design-system/src/components/InlineEditing/Primitives/InlineEditingPrimitive.tsx +++ b/packages/design-system/src/components/InlineEditing/Primitives/InlineEditingPrimitive.tsx @@ -43,6 +43,7 @@ export type InlineEditingPrimitiveProps = { onToggle?: (isEditionMode: boolean) => void; label: string; required?: boolean; + maxLength?: number; placeholder: string; ariaLabel?: string; renderValueAs?: ElementType | ReactElement; @@ -85,6 +86,7 @@ const InlineEditingPrimitive = forwardRef( onCancel = () => {}, onToggle = () => {}, required = false, + maxLength, label, hasError, description, @@ -176,6 +178,7 @@ const InlineEditingPrimitive = forwardRef( label, name: label.replace(/\s/g, ''), required, + maxLength, placeholder, onChange: (event: ChangeEvent | ChangeEvent): void => { if (onChangeValue) { diff --git a/packages/design-system/src/components/InlineEditing/variations/InlineEditing.textarea.cy.tsx b/packages/design-system/src/components/InlineEditing/variations/InlineEditing.textarea.cy.tsx new file mode 100644 index 00000000000..21f0dacdbf2 --- /dev/null +++ b/packages/design-system/src/components/InlineEditing/variations/InlineEditing.textarea.cy.tsx @@ -0,0 +1,41 @@ +import InlineEditingMulti from './InlineEditing.textarea'; + +context('', () => { + const defaultProps = { + label: 'Textarea inline edit', + placeholder: 'Type here', + }; + + it('should render with filled value', () => { + cy.mount(); + + cy.get('[data-testid="inlineediting.button.edit"]').should('exist'); + cy.get('p').should('have.text', 'Some text'); + }); + + it('should allow inline editing', () => { + cy.mount(); + + // Switch to edit mode + cy.get('[data-testid="inlineediting.button.edit"]').click(); + cy.get('[data-testid="inlineediting.textarea"]').should('be.visible'); + cy.get('[data-testid="inlineediting.button.cancel"]').should('be.visible'); + cy.get('[data-testid="inlineediting.button.submit"]').should('be.visible'); + + // Input some text and submit + cy.get('[data-testid="inlineediting.textarea"]').type('Here is a description'); + cy.get('[data-testid="inlineediting.button.submit"]').click(); + + cy.get('p').should('have.text', 'Here is a description'); + }); + + it('should allow to have some constraints', () => { + cy.mount(); + + cy.get('[data-testid="inlineediting.button.edit"]').click(); + cy.get('[data-testid="inlineediting.textarea"]').should('have.attr', 'required'); + cy.get('[data-testid="inlineediting.textarea"]') + .invoke('attr', 'maxLength') + .should('equal', '10'); + }); +});