Skip to content

Commit cb848f0

Browse files
authored
Merge pull request #467 from rvsia/fixDualListSelectNative
fix(pf4): use custom divs for dual list select
2 parents 38ec9cc + 9615b32 commit cb848f0

File tree

5 files changed

+335
-249
lines changed

5 files changed

+335
-249
lines changed

packages/pf4-component-mapper/src/files/dual-list-select.js

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -41,20 +41,27 @@ const getOptionsGroup = (value, lastClicked, options) => {
4141
return [...options.slice(startIndex, endIndex).map(({ value }) => value.toString())];
4242
};
4343

44-
const List = ({ value, optionClick, noOptionsTitle, filterValue, filterValueText, ...rest }) => (
45-
<select className="pf-c-form-control pf-u-pr-sm ddorg__pf4-component-mapper__dual-list-select" multiple {...rest}>
44+
const List = ({ value, optionClick, noOptionsTitle, filterValue, filterValueText, selectedValues, ...rest }) => (
45+
<div className="pf-c-form-control pf-u-pr-sm ddorg__pf4-component-mapper__dual-list-select" {...rest}>
4646
{value.length < 1 && (
47-
<option className="ddorg__pf4-component-mapper__dual-list-select-option" disabled>
47+
<div className="ddorg__pf4-component-mapper__dual-list-select-option-text ddorg__pf4-component-mapper__dual-list-select-option-disabled">
4848
{filterValue ? filterValueText : noOptionsTitle}
49-
</option>
49+
</div>
5050
)}
5151
{value.length > 0 &&
5252
value.map(({ value, label }) => (
53-
<option onClick={optionClick} key={value} value={value}>
53+
<div
54+
onClick={(e) => optionClick(e, value)}
55+
key={value}
56+
value={value}
57+
className={`ddorg__pf4-component-mapper__dual-list-select-option ${
58+
selectedValues.includes(value) ? 'ddorg__pf4-component-mapper__dual-list-select-option-selected' : ''
59+
}`}
60+
>
5461
{label}
55-
</option>
62+
</div>
5663
))}
57-
</select>
64+
</div>
5865
);
5966

6067
List.propTypes = {
@@ -67,7 +74,8 @@ List.propTypes = {
6774
optionClick: PropTypes.func.isRequired,
6875
noOptionsTitle: PropTypes.node,
6976
filterValue: PropTypes.string,
70-
filterValueText: PropTypes.node
77+
filterValueText: PropTypes.node,
78+
selectedValues: PropTypes.array
7179
};
7280

7381
List.defaultProps = {
@@ -181,7 +189,6 @@ const DualList = (props) => {
181189
moveLeftTitle,
182190
options,
183191
rightTitle,
184-
size,
185192
label,
186193
isRequired,
187194
helperText,
@@ -199,10 +206,7 @@ const DualList = (props) => {
199206

200207
const showError = touched && error;
201208

202-
const handleOptionClicked = (event, options, isRight) => {
203-
const {
204-
target: { value }
205-
} = event;
209+
const handleOptionClicked = (event, value, options, isRight) => {
206210
const selectedKey = isRight ? 'selectedLeftValues' : 'selectedRightValues';
207211
const lastKey = isRight ? 'lastLeftClicked' : 'lastRightClicked';
208212
if (event.shiftKey && state[lastKey]) {
@@ -266,12 +270,12 @@ const DualList = (props) => {
266270
</GridItem>
267271
<GridItem md={12}>
268272
<List
269-
size={size}
270-
optionClick={(event) => handleOptionClicked(event, leftValues, true)}
273+
optionClick={(event, value) => handleOptionClicked(event, value, leftValues, true)}
271274
value={leftValues}
272275
noOptionsTitle={noOptionsTitle}
273276
filterValue={state.filterOptions}
274277
filterValueText={filterOptionsText}
278+
selectedValues={state.selectedLeftValues}
275279
/>
276280
</GridItem>
277281
</Grid>
@@ -341,12 +345,12 @@ const DualList = (props) => {
341345
</GridItem>
342346
<GridItem md={12}>
343347
<List
344-
size={size}
345-
optionClick={(event) => handleOptionClicked(event, rightValues, false)}
348+
optionClick={(event, value) => handleOptionClicked(event, value, rightValues, false)}
346349
value={rightValues}
347350
noOptionsTitle={noValueTitle}
348351
filterValue={state.filterValue}
349352
filterValueText={filterValueText}
353+
selectedValues={state.selectedRightValues}
350354
/>
351355
</GridItem>
352356
</Grid>
@@ -366,7 +370,6 @@ DualList.propTypes = {
366370
),
367371
leftTitle: PropTypes.node,
368372
rightTitle: PropTypes.node,
369-
size: PropTypes.number,
370373
moveLeftTitle: PropTypes.node,
371374
moveRightTitle: PropTypes.node,
372375
clearRightValue: PropTypes.bool,
@@ -387,7 +390,6 @@ DualList.propTypes = {
387390
DualList.defaultProps = {
388391
leftTitle: 'Options',
389392
rightTitle: 'Selected',
390-
size: 15,
391393
moveLeftTitle: 'Move selected to left',
392394
moveRightTitle: 'Move selected to right',
393395
moveAllRightTitle: 'Move all to right',

packages/pf4-component-mapper/src/files/dual-list-select.scss

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,23 @@
55
.ddorg__pf4-component-mapper__dual-list-select {
66
height: 300px !important;
77
background: none !important;
8+
overflow: auto !important;
89
}
910

10-
.ddorg__pf4-component-mapper__dual-list-select-option {
11+
.ddorg__pf4-component-mapper__dual-list-select-option-text {
1112
height: 100% !important;
1213
}
14+
15+
.ddorg__pf4-component-mapper__dual-list-select-option {
16+
cursor: pointer;
17+
user-select: none;
18+
}
19+
20+
.ddorg__pf4-component-mapper__dual-list-select-option-disabled {
21+
color: var(--pf-global--disabled-color--100)
22+
}
23+
24+
.ddorg__pf4-component-mapper__dual-list-select-option-selected {
25+
background-color: var(--pf-global--active-color--400);
26+
color: white
27+
}

0 commit comments

Comments
 (0)