Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(components): make AutocompleteInput compatible with new clear option #558

Merged
merged 3 commits into from
Mar 30, 2020
Merged
Show file tree
Hide file tree
Changes from all 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
7 changes: 7 additions & 0 deletions src/__snapshots__/storyshots.spec.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -15818,6 +15818,7 @@ label + .circuit-3 {
class="circuit-1 circuit-2"
id="3"
role="combobox"
type="text"
value=""
/>
</div>
Expand Down Expand Up @@ -15936,6 +15937,7 @@ label + .circuit-3 {
class="circuit-1 circuit-2"
id="1"
role="combobox"
type="text"
value=""
/>
</div>
Expand Down Expand Up @@ -16054,6 +16056,7 @@ label + .circuit-3 {
class="circuit-1 circuit-2"
id="2"
role="combobox"
type="text"
value=""
/>
</div>
Expand Down Expand Up @@ -16161,6 +16164,7 @@ label + .circuit-3 {
class="circuit-1 circuit-2"
id="downshift-3-input"
role="combobox"
type="text"
value=""
/>
</div>
Expand Down Expand Up @@ -17247,6 +17251,7 @@ label + .circuit-3 {
class="circuit-1 circuit-2"
id="38"
placeholder="Search..."
type="text"
value=""
/>
</div>
Expand Down Expand Up @@ -17347,6 +17352,7 @@ label + .circuit-3 {
class="circuit-1 circuit-2"
id="40"
placeholder="Search..."
type="text"
value=""
/>
</div>
Expand Down Expand Up @@ -17452,6 +17458,7 @@ label + .circuit-3 {
disabled=""
id="39"
placeholder="Search..."
type="text"
value=""
/>
</div>
Expand Down
11 changes: 2 additions & 9 deletions src/components/AutoCompleteInput/AutoCompleteInput.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import Downshift from 'downshift';
import { includes, isString, isEmpty } from 'lodash/fp';

import SearchInput from '../SearchInput';
import CloseButton from '../CloseButton';
import Card from '../Card';
import Text from '../Text';
import {
Expand All @@ -44,11 +43,6 @@ const autoCompleteWrapperStyles = ({ theme }) => css`

const AutoCompleteWrapper = styled('div')(autoCompleteWrapperStyles);

const ClearButton = styled(CloseButton)`
label: input__button-clear;
pointer-events: all !important;
`;

const optionsStyles = ({ theme }) => css`
label: input__options;
position: absolute;
Expand Down Expand Up @@ -192,8 +186,7 @@ export default class AutoCompleteInput extends Component {
...inputProps
} = this.props;

const renderSuffix = props =>
showClear ? <ClearButton {...props} onClick={this.handleClear} /> : null;
const onClear = showClear ? this.handleClear : null;

return (
<Downshift
Expand All @@ -216,8 +209,8 @@ export default class AutoCompleteInput extends Component {
<AutoCompleteWrapper {...getRootProps({ refKey: 'innerRef' })}>
<SearchInput
{...getInputProps(inputProps)}
onClear={onClear}
noMargin
renderSuffix={renderSuffix}
/>
{isOpen && !isEmpty(maxOptions) && (
<Options spacing={Card.MEGA}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ const AsyncAutoCompleteInput = () => {
onChange={action('handleChange')}
onInputValueChange={handleInputValueChange}
filterOptions={opts => opts}
showClear
/>
);
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ label + .circuit-3 {
class="circuit-1 circuit-2"
id="downshift-0-input"
role="combobox"
type="text"
value=""
/>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ label + .circuit-3 {
class="circuit-1 circuit-2"
id="downshift-0-input"
role="combobox"
type="text"
value=""
/>
</div>
Expand Down
1 change: 1 addition & 0 deletions src/components/SearchInput/SearchInput.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ const StyledClearIcon = styled(ClearIcon)`
const SearchInput = ({ children, value, onClear, ...props }) => (
<Input
value={value}
type="text"
renderPrefix={({ className }) => <SearchIcon {...{ className }} />}
renderSuffix={({ className }) =>
value && onClear ? (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ label + .circuit-5 {
<input
aria-invalid="false"
class="circuit-1 circuit-2"
type="text"
value="search value"
/>
<div
Expand Down Expand Up @@ -189,6 +190,7 @@ label + .circuit-3 {
aria-invalid="false"
class="circuit-1 circuit-2"
disabled=""
type="text"
value=""
/>
</div>
Expand Down Expand Up @@ -275,6 +277,7 @@ label + .circuit-3 {
<input
aria-invalid="false"
class="circuit-1 circuit-2"
type="text"
value=""
/>
</div>
Expand Down