diff --git a/src/ComboboxInput/ComboboxInput.js b/src/ComboboxInput/ComboboxInput.js index 38964b506..96b03d69b 100644 --- a/src/ComboboxInput/ComboboxInput.js +++ b/src/ComboboxInput/ComboboxInput.js @@ -71,7 +71,7 @@ const ComboboxInput = React.forwardRef(({ {validationState.text} } - + {options.map(option => ( + widthSizingType='minTarget' /> ); }); diff --git a/src/InputGroup/InputGroup.js b/src/InputGroup/InputGroup.js index 7f21e02dd..82a51da3a 100644 --- a/src/InputGroup/InputGroup.js +++ b/src/InputGroup/InputGroup.js @@ -40,7 +40,8 @@ class InputGroup extends Component { const getClassName = (child) => classnames( { - 'fd-input-group__input': child.type.displayName !== InputGroupAddon.displayName + 'fd-input-group__input': child.type.displayName !== InputGroupAddon.displayName && + !child.props.className?.includes('fd-tokenizer') }, child.props.className ); diff --git a/src/MultiInput/MultiInput.js b/src/MultiInput/MultiInput.js index d140303e3..b2fa39095 100644 --- a/src/MultiInput/MultiInput.js +++ b/src/MultiInput/MultiInput.js @@ -48,13 +48,23 @@ class MultiInput extends Component { // create tag elements to display below input box createTags = () => { - return this.state.tags.map((tag, index) => ( - this.removeTag(tag)}> - {tag} - - )); + return this.state.tags.map((tag, index) => { + if (index < 3) { + return ( + this.removeTag(tag)}> + {tag} + + ); + } else if (index >= this.state.tags.length - 1) { + return ( + {this.state.tags.length - 3} more + ); + } else { + return null; + } + }); }; // add/remove tag to tag collection @@ -95,7 +105,6 @@ class MultiInput extends Component { // remove/close tag removeTag = (tag) => { - this.setState( prevState => { const tags = prevState.tags.filter(item => { @@ -201,7 +210,7 @@ class MultiInput extends Component { {this.state.tags.length > 0 && this.createTags()} diff --git a/src/MultiInput/MultiInput.test.js b/src/MultiInput/MultiInput.test.js index ee9f0c784..d5093e8bb 100644 --- a/src/MultiInput/MultiInput.test.js +++ b/src/MultiInput/MultiInput.test.js @@ -136,6 +136,38 @@ describe('', () => { ); }); + test('tag list is truncated when more than 3 options are selected', () => { + wrapper = mount(multiInput); + wrapper + .find('button.fd-button--transparent') + .simulate('click'); + + // add 4 tags to list + wrapper + .find('.fd-checkbox').first() + .simulate('change', { target: { value: data[0] } }); + wrapper + .find('.fd-checkbox').at(1) + .simulate('change', { target: { value: data[0] } }); + wrapper + .find('.fd-checkbox').at(2) + .simulate('change', { target: { value: data[0] } }); + wrapper + .find('.fd-checkbox').at(3) + .simulate('change', { target: { value: data[0] } }); + + // check that tag list contains value + expect(wrapper.state(['tags'])).toHaveLength(4); + + // check to see that only 3 tags are created + expect(wrapper.find('span.fd-token[role="button"]')).toHaveLength(3); + + // check that truncated text is correct + expect(wrapper.find('span.fd-tokenizer__indicator').text()).toEqual( + '1 more' + ); + }); + test('remove tag from taglist by unchecking', () => { wrapper = mount(multiInput); wrapper diff --git a/src/MultiInput/__stories__/__snapshots__/MultiInput.stories.storyshot b/src/MultiInput/__stories__/__snapshots__/MultiInput.stories.storyshot index 8e9c32934..14c5aef47 100644 --- a/src/MultiInput/__stories__/__snapshots__/MultiInput.stories.storyshot +++ b/src/MultiInput/__stories__/__snapshots__/MultiInput.stories.storyshot @@ -26,14 +26,14 @@ exports[`Storyshots Component API/MultiInput Compact 1`] = ` tabIndex={0} >
@@ -80,7 +80,7 @@ exports[`Storyshots Component API/MultiInput Dev 1`] = ` tabIndex={0} >
@@ -88,7 +88,7 @@ exports[`Storyshots Component API/MultiInput Dev 1`] = ` className="fd-tokenizer__inner" > @@ -136,14 +136,14 @@ exports[`Storyshots Component API/MultiInput Disabled 1`] = ` tabIndex={0} >
@@ -191,13 +191,13 @@ exports[`Storyshots Component API/MultiInput Primary 1`] = ` tabIndex={0} >
@@ -247,13 +247,13 @@ exports[`Storyshots Component API/MultiInput Validation States 1`] = ` tabIndex={0} >
@@ -300,13 +300,13 @@ exports[`Storyshots Component API/MultiInput Validation States 1`] = ` tabIndex={0} >
@@ -353,13 +353,13 @@ exports[`Storyshots Component API/MultiInput Validation States 1`] = ` tabIndex={0} >
@@ -406,13 +406,13 @@ exports[`Storyshots Component API/MultiInput Validation States 1`] = ` tabIndex={0} >
diff --git a/src/SearchInput/SearchInput.js b/src/SearchInput/SearchInput.js index a3ae6f6b6..f6cf205ac 100644 --- a/src/SearchInput/SearchInput.js +++ b/src/SearchInput/SearchInput.js @@ -206,7 +206,7 @@ class SearchInput extends Component { noArrow onClickOutside={this.handleClickOutside} show={this.state.isExpanded} - widthSizingType='matchTarget' /> + widthSizingType='minTarget' />
); } diff --git a/src/Select/Select.js b/src/Select/Select.js index f02a32500..edbedd4ab 100644 --- a/src/Select/Select.js +++ b/src/Select/Select.js @@ -125,7 +125,7 @@ const Select = React.forwardRef(({ placement='bottom-start' popperProps={{ id }} show={isExpanded} - widthSizingType='matchTarget' /> + widthSizingType='minTarget' /> ); });