Skip to content

Commit a704938

Browse files
committed
fix(pf4): added clearbale prop to downshift
1 parent 5e11d88 commit a704938

File tree

4 files changed

+41
-14
lines changed

4 files changed

+41
-14
lines changed

packages/pf4-component-mapper/demo/demo-schemas/select-schema.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,13 @@ const selectSchema = {
3737
label: 'Disabled-select',
3838
options,
3939
isDisabled: true
40+
},
41+
{
42+
component: componentTypes.SELECT,
43+
name: 'clearable-select',
44+
label: 'Clearable-select',
45+
options,
46+
isClearable: true
4047
}
4148
]
4249
};
Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,23 @@
11
import React from 'react';
22
import PropTypes from 'prop-types';
33

4-
import { Button, ButtonVariant } from '@patternfly/react-core';
5-
64
import { TimesCircleIcon } from '@patternfly/react-icons';
5+
import './clear-indicator.scss';
76

8-
const ClearIndicator = ({ clearValue, innerProps: { ref, ...restInnerProps } }) => (
9-
<Button {...restInnerProps} onClick={clearValue} variant={ButtonVariant.plain}>
7+
const ClearIndicator = ({ clearSelection }) => (
8+
<span
9+
onClick={(event) => {
10+
clearSelection();
11+
event.stopPropagation();
12+
}}
13+
className="ddorg__pf4-component-mapper__select-clear-indicator pf-u-pr-md pf-u-pl-md"
14+
>
1015
<TimesCircleIcon />
11-
</Button>
16+
</span>
1217
);
1318

1419
ClearIndicator.propTypes = {
15-
innerProps: PropTypes.object.isRequired,
16-
clearValue: PropTypes.func
17-
};
18-
19-
ClearIndicator.defaultProps = {
20-
clearValue: () => undefined
20+
clearSelection: PropTypes.func.isRequired
2121
};
2222

2323
export default ClearIndicator;
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
.ddorg__pf4-component-mapper__select-clear-indicator {
2+
position: relative;
3+
display: inline-block;
4+
> svg {
5+
fill: var(--pf-global--palette--black-600)
6+
}
7+
&:hover > svg {
8+
fill: inherit
9+
}
10+
&::before {
11+
position: absolute;
12+
top: 0;
13+
bottom: 0;
14+
left: 0;
15+
right: 0;
16+
}
17+
}

packages/pf4-component-mapper/src/common/select/select.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,9 @@ import '@patternfly/react-styles/css/components/Select/select.css';
1010
import './select-styles.scss';
1111
import Input from './input';
1212
import Menu from './menu';
13+
import ClearIndicator from './clear-indicator';
1314

14-
const InternalSelect = ({ onChange, options, value, simpleValue, placeholder, isSearchable, isDisabled, ...props }) => {
15+
const InternalSelect = ({ onChange, options, value, simpleValue, placeholder, isSearchable, isDisabled, isClearable, ...props }) => {
1516
// console.log(props);
1617
const inputRef = useRef();
1718
const parsedValue = parseInternalValue(value);
@@ -23,7 +24,7 @@ const InternalSelect = ({ onChange, options, value, simpleValue, placeholder, is
2324
}}
2425
selectedItem={value}
2526
>
26-
{({ isOpen, getLabelProps, getInputProps, getToggleButtonProps, getItemProps, highlightedIndex, selectedItem }) => {
27+
{({ isOpen, clearSelection, getInputProps, getToggleButtonProps, getItemProps, highlightedIndex }) => {
2728
const toggleButtonProps = { ...getToggleButtonProps() };
2829
const enhancedToggleButtonProps = {
2930
...toggleButtonProps,
@@ -51,6 +52,7 @@ const InternalSelect = ({ onChange, options, value, simpleValue, placeholder, is
5152
/>
5253
</div>
5354
<span className="pf-c-select__toggle-arrow">
55+
{isClearable && parsedValue && <ClearIndicator clearSelection={clearSelection} />}
5456
<CaretDownIcon />
5557
</span>
5658
</button>
@@ -76,7 +78,8 @@ InternalSelect.propTypes = {
7678
isSearchable: PropTypes.bool,
7779
id: PropTypes.string,
7880
name: PropTypes.string.isRequired,
79-
isDisabled: PropTypes.bool
81+
isDisabled: PropTypes.bool,
82+
isClearable: PropTypes.bool
8083
};
8184

8285
const Select = ({ selectVariant, menuIsPortal, ...props }) => {

0 commit comments

Comments
 (0)