Skip to content
Closed
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
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ export interface SelectProps
width?: string | number;
/** Max height of the select container as a number of px or string percentage */
maxHeight?: string | number;
/** If true, only show count of selections rather than selected values. Default to false. */
showOnlySelectionCount?: boolean;
/** Icon element to render inside the select toggle */
toggleIcon?: React.ReactElement;
/** Custom content to render in the select menu. If this prop is defined, the variant prop will be ignored and the select will render with a single select toggle */
Expand Down Expand Up @@ -120,6 +122,7 @@ class Select extends React.Component<SelectProps & InjectedOuiaProps, SelectStat
width: '',
onClear: (_e: React.MouseEvent) => undefined as void,
onCreateOption: (_newOptionValue: string) => undefined as void,
showOnlySelectionCount: false,
toggleIcon: null as React.ReactElement,
onFilter: null,
customContent: null
Expand Down Expand Up @@ -356,6 +359,7 @@ class Select extends React.Component<SelectProps & InjectedOuiaProps, SelectStat
ouiaId,
createText,
noResultsFoundText,
showOnlySelectionCount,
...props
} = this.props;
const { openedOnEnter, typeaheadInputValue, typeaheadActiveChild } = this.state;
Expand All @@ -370,7 +374,7 @@ class Select extends React.Component<SelectProps & InjectedOuiaProps, SelectStat
}
}
let selectedChips = null;
if (variant === SelectVariant.typeaheadMulti) {
if (variant === SelectVariant.typeaheadMulti && !showOnlySelectionCount) {
selectedChips = (
<ChipGroup>
{selections &&
Expand Down Expand Up @@ -484,6 +488,11 @@ class Select extends React.Component<SelectProps & InjectedOuiaProps, SelectStat
<div className={css(styles.selectToggleWrapper)}>
{toggleIcon && <span className={css(styles.selectToggleIcon)}>{toggleIcon}</span>}
{selections && (Array.isArray(selections) && selections.length > 0) && selectedChips}
{selections && showOnlySelectionCount && (Array.isArray(selections) && selections.length > 0) && (
<div className={css(styles.selectToggleBadge)}>
<span className={css(badgeStyles.badge, badgeStyles.modifiers.read)}>{selections.length}</span>
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just curious, why did you not do <Badge isRead>{selections.length}</Badge> instead of using css classes?

</div>
)}
<input
className={css(formStyles.formControl, styles.selectToggleTypeahead)}
aria-activedescendant={typeaheadActiveChild && typeaheadActiveChild.id}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ exports[`checkbox select renders checkbox select groups successfully - old class
}
placeholderText=""
selections=""
showOnlySelectionCount={false}
toggleIcon={null}
toggleId={null}
variant="checkbox"
Expand Down Expand Up @@ -916,6 +917,7 @@ exports[`checkbox select renders checkbox select groups successfully 1`] = `
}
placeholderText=""
selections=""
showOnlySelectionCount={false}
toggleIcon={null}
toggleId={null}
variant="checkbox"
Expand Down Expand Up @@ -1639,6 +1641,7 @@ exports[`checkbox select renders closed successfully - old classes 1`] = `
}
placeholderText=""
selections=""
showOnlySelectionCount={false}
toggleIcon={null}
toggleId={null}
variant="checkbox"
Expand Down Expand Up @@ -1868,6 +1871,7 @@ exports[`checkbox select renders closed successfully 1`] = `
}
placeholderText=""
selections=""
showOnlySelectionCount={false}
toggleIcon={null}
toggleId={null}
variant="checkbox"
Expand Down Expand Up @@ -2083,6 +2087,7 @@ exports[`checkbox select renders expanded successfully - old classes 1`] = `
}
placeholderText=""
selections=""
showOnlySelectionCount={false}
toggleIcon={null}
toggleId={null}
variant="checkbox"
Expand Down Expand Up @@ -2540,6 +2545,7 @@ exports[`checkbox select renders expanded successfully 1`] = `
}
placeholderText=""
selections=""
showOnlySelectionCount={false}
toggleIcon={null}
toggleId={null}
variant="checkbox"
Expand Down Expand Up @@ -3020,6 +3026,7 @@ exports[`checkbox select renders expanded successfully with custom objects 1`] =
}
placeholderText=""
selections=""
showOnlySelectionCount={false}
toggleIcon={null}
toggleId={null}
variant="checkbox"
Expand Down Expand Up @@ -3468,6 +3475,7 @@ exports[`select custom select filter filters properly 1`] = `
}
placeholderText=""
selections=""
showOnlySelectionCount={false}
toggleIcon={null}
toggleId={null}
variant="typeahead"
Expand Down Expand Up @@ -3948,6 +3956,7 @@ exports[`select renders select groups successfully 1`] = `
}
placeholderText=""
selections=""
showOnlySelectionCount={false}
toggleIcon={null}
toggleId={null}
variant="single"
Expand Down Expand Up @@ -4609,6 +4618,7 @@ exports[`select renders up drection successfully 1`] = `
}
placeholderText=""
selections=""
showOnlySelectionCount={false}
toggleIcon={null}
toggleId={null}
variant="single"
Expand Down Expand Up @@ -4842,6 +4852,7 @@ exports[`select single select renders closed successfully 1`] = `
}
placeholderText=""
selections=""
showOnlySelectionCount={false}
toggleIcon={null}
toggleId={null}
variant="single"
Expand Down Expand Up @@ -5077,6 +5088,7 @@ exports[`select single select renders disabled successfully 1`] = `
}
placeholderText=""
selections=""
showOnlySelectionCount={false}
toggleIcon={null}
toggleId={null}
variant="single"
Expand Down Expand Up @@ -5313,6 +5325,7 @@ exports[`select single select renders expanded successfully 1`] = `
}
placeholderText=""
selections=""
showOnlySelectionCount={false}
toggleIcon={null}
toggleId={null}
variant="single"
Expand Down Expand Up @@ -5755,6 +5768,7 @@ exports[`select single select renders expanded successfully with custom objects
}
placeholderText=""
selections=""
showOnlySelectionCount={false}
toggleIcon={null}
toggleId={null}
variant="single"
Expand Down Expand Up @@ -6104,6 +6118,7 @@ exports[`select with custom content renders closed successfully 1`] = `
}
placeholderText=""
selections=""
showOnlySelectionCount={false}
toggleIcon={null}
toggleId={null}
variant="single"
Expand Down Expand Up @@ -6274,6 +6289,7 @@ exports[`select with custom content renders expanded successfully 1`] = `
}
placeholderText=""
selections=""
showOnlySelectionCount={false}
toggleIcon={null}
toggleId={null}
variant="single"
Expand Down Expand Up @@ -6567,6 +6583,7 @@ exports[`typeahead multi select renders closed successfully 1`] = `
}
placeholderText=""
selections=""
showOnlySelectionCount={false}
toggleIcon={null}
toggleId={null}
variant="typeaheadmulti"
Expand Down Expand Up @@ -6607,6 +6624,7 @@ exports[`typeahead multi select renders closed successfully 1`] = `
class="pf-c-select__toggle-wrapper"
>


<input
aria-label=""
autocomplete="off"
Expand Down Expand Up @@ -6826,6 +6844,7 @@ exports[`typeahead multi select renders expanded successfully 1`] = `
}
placeholderText=""
selections=""
showOnlySelectionCount={false}
toggleIcon={null}
toggleId={null}
variant="typeaheadmulti"
Expand Down Expand Up @@ -6866,6 +6885,7 @@ exports[`typeahead multi select renders expanded successfully 1`] = `
class="pf-c-select__toggle-wrapper"
>


<input
aria-label=""
autocomplete="off"
Expand Down Expand Up @@ -7300,6 +7320,7 @@ exports[`typeahead multi select renders selected successfully 1`] = `
"Mrs",
]
}
showOnlySelectionCount={false}
toggleIcon={null}
toggleId={null}
variant="typeaheadmulti"
Expand Down Expand Up @@ -8305,6 +8326,7 @@ exports[`typeahead multi select test onChange 1`] = `
}
placeholderText=""
selections=""
showOnlySelectionCount={false}
toggleIcon={null}
toggleId={null}
variant="typeahead"
Expand Down Expand Up @@ -8629,6 +8651,7 @@ exports[`typeahead select renders closed successfully 1`] = `
}
placeholderText=""
selections=""
showOnlySelectionCount={false}
toggleIcon={null}
toggleId={null}
variant="typeahead"
Expand Down Expand Up @@ -8887,6 +8910,7 @@ exports[`typeahead select renders expanded successfully 1`] = `
}
placeholderText=""
selections=""
showOnlySelectionCount={false}
toggleIcon={null}
toggleId={null}
variant="typeahead"
Expand Down Expand Up @@ -9347,6 +9371,7 @@ exports[`typeahead select renders selected successfully 1`] = `
}
placeholderText=""
selections="Mr"
showOnlySelectionCount={false}
toggleIcon={null}
toggleId={null}
variant="typeahead"
Expand Down Expand Up @@ -9903,6 +9928,7 @@ exports[`typeahead select test creatable option 1`] = `
}
placeholderText=""
selections=""
showOnlySelectionCount={false}
toggleIcon={null}
toggleId={null}
variant="typeahead"
Expand Down Expand Up @@ -10237,6 +10263,7 @@ exports[`typeahead select test onChange 1`] = `
}
placeholderText=""
selections=""
showOnlySelectionCount={false}
toggleIcon={null}
toggleId={null}
variant="typeahead"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -537,7 +537,8 @@ class MultiTypeaheadSelectInput extends React.Component {
isExpanded: false,
selected: [],
isCreatable: false,
hasOnCreateOption: false
hasOnCreateOption: false,
showOnlySelectionCount: false
};

this.onCreateOption = newValue => {
Expand Down Expand Up @@ -585,10 +586,16 @@ class MultiTypeaheadSelectInput extends React.Component {
hasOnCreateOption: checked
});
};

this.toggleShowOnlyCount = checked => {
this.setState({
showOnlySelectionCount: checked
});
};
}

render() {
const { isExpanded, selected, isCreatable, hasOnCreateOption } = this.state;
const { isExpanded, selected, isCreatable, hasOnCreateOption, showOnlySelectionCount } = this.state;
const titleId = 'multi-typeahead-select-id';

return (
Expand All @@ -608,6 +615,7 @@ class MultiTypeaheadSelectInput extends React.Component {
placeholderText="Select a state"
isCreatable={isCreatable}
onCreateOption={(hasOnCreateOption && this.onCreateOption) || undefined}
showOnlySelectionCount={showOnlySelectionCount}
>
{this.state.options.map((option, index) => (
<SelectOption isDisabled={option.disabled} key={index} value={option.value} />
Expand All @@ -629,6 +637,14 @@ class MultiTypeaheadSelectInput extends React.Component {
id="toggle-new-typeahead-multi"
name="toggle-new-typeahead-multi"
/>
<Checkbox
label="showOnlySelectionCount"
isChecked={this.state.showOnlySelectionCount}
onChange={this.toggleShowOnlyCount}
aria-label="toggle show only selection count checkbox"
id="toggle-show-only-selection-count-multi"
name="toggle-show-selection-count-multi"
/>
</div>
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,7 @@ exports[`data toolbar DataToolbarFilter 1`] = `
}
placeholderText=""
selections="Running"
showOnlySelectionCount={false}
toggleIcon={null}
toggleId={null}
variant="single"
Expand Down Expand Up @@ -935,6 +936,7 @@ exports[`data toolbar DataToolbarFilter 1`] = `
}
placeholderText=""
selections="Low"
showOnlySelectionCount={false}
toggleIcon={null}
toggleId={null}
variant="single"
Expand Down Expand Up @@ -2366,6 +2368,7 @@ exports[`data toolbar DataToolbarToggleGroup 1`] = `
}
placeholderText=""
selections="Running"
showOnlySelectionCount={false}
toggleIcon={null}
toggleId={null}
variant="single"
Expand Down Expand Up @@ -2580,6 +2583,7 @@ exports[`data toolbar DataToolbarToggleGroup 1`] = `
}
placeholderText=""
selections="Low"
showOnlySelectionCount={false}
toggleIcon={null}
toggleId={null}
variant="single"
Expand Down