From 6670f90946172c7c0cff16aaae3eccece2373883 Mon Sep 17 00:00:00 2001 From: Tanner Summers Date: Thu, 6 Jan 2022 16:38:09 -0600 Subject: [PATCH 1/8] feat(textarea): added char counter this includes ui changes, test, and styles --- .../src/components/text-area/_text-area.scss | 8 +++ .../__snapshots__/PublicAPI-test.js.snap | 2 + .../src/components/TextArea/TextArea-story.js | 5 ++ .../src/components/TextArea/TextArea-test.js | 55 +++++++++++++++++++ .../react/src/components/TextArea/TextArea.js | 37 ++++++++++++- .../scss/components/text-area/_text-area.scss | 8 +++ 6 files changed, 112 insertions(+), 3 deletions(-) diff --git a/packages/components/src/components/text-area/_text-area.scss b/packages/components/src/components/text-area/_text-area.scss index aa35058b5330..3f857b73a5b9 100644 --- a/packages/components/src/components/text-area/_text-area.scss +++ b/packages/components/src/components/text-area/_text-area.scss @@ -99,6 +99,14 @@ color: transparent; } } + + .#{$prefix}--text-area__counter-wrapper { + width: 100%; + } + + .#{$prefix}--text-area__counter { + float: right; + } } @include exports('text-area') { diff --git a/packages/react/__tests__/__snapshots__/PublicAPI-test.js.snap b/packages/react/__tests__/__snapshots__/PublicAPI-test.js.snap index 7023b66fdea7..0624d5b66281 100644 --- a/packages/react/__tests__/__snapshots__/PublicAPI-test.js.snap +++ b/packages/react/__tests__/__snapshots__/PublicAPI-test.js.snap @@ -6196,10 +6196,12 @@ Map { "defaultProps": Object { "cols": 50, "disabled": false, + "enableCounter": false, "helperText": "", "invalid": false, "invalidText": "", "light": false, + "maxCount": undefined, "onChange": [Function], "onClick": [Function], "placeholder": "", diff --git a/packages/react/src/components/TextArea/TextArea-story.js b/packages/react/src/components/TextArea/TextArea-story.js index d9914b8e8ad3..1a6a29b5a267 100644 --- a/packages/react/src/components/TextArea/TextArea-story.js +++ b/packages/react/src/components/TextArea/TextArea-story.js @@ -27,6 +27,11 @@ const TextAreaProps = () => ({ ), helperText: text('Helper text (helperText)', 'Optional helper text.'), placeholder: text('Placeholder text (placeholder)', 'Placeholder text.'), + enableCounter: boolean( + 'Enable character counter/limit (enableCounter)', + false + ), + maxCount: text('Character limit (maxCount)', ''), id: 'test2', cols: number('Columns (columns)', 50), rows: number('Rows (rows)', 4), diff --git a/packages/react/src/components/TextArea/TextArea-test.js b/packages/react/src/components/TextArea/TextArea-test.js index aac158b307b8..59229b396ad3 100644 --- a/packages/react/src/components/TextArea/TextArea-test.js +++ b/packages/react/src/components/TextArea/TextArea-test.js @@ -76,6 +76,16 @@ describe('TextArea', () => { wrapper.setProps({ light: true }); expect(wrapper.props().light).toEqual(true); }); + + it('should set enableCounter as expected', () => { + wrapper.setProps({ enableCounter: true }); + expect(wrapper.props().enableCounter).toEqual(true); + }); + + it('should set maxCount as expected', () => { + wrapper.setProps({ maxCount: 5 }); + expect(wrapper.props().maxCount).toEqual(5); + }); }); describe('label', () => { @@ -117,6 +127,51 @@ describe('TextArea', () => { expect(renderedHelper.text()).toEqual('Helper text'); }); }); + + describe('counter', () => { + const counterTestWrapper1 = mount( +