FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

fix(chipGroup): Allow variable number of chips to be displayed by jessiehuff · Pull Request #2878 · patternfly/patternfly-react · GitHub

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .snap  (2) .tsx  (2) All 2 file types selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
      • ChipGroup.test.tsx
      • ChipGroup.tsx
      • Select.test.tsx.snap
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ describe('ChipGroup', () => {
<ChipGroup>
<Chip>1</Chip>
<Chip>2</Chip>
<Chip>3</Chip>
<Chip>4</Chip>
</ChipGroup>
);
const overflowButton = view.find('.pf-m-overflow .pf-c-chip__text');
Expand Down
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ export interface ChipGroupProps extends React.HTMLProps<HTMLDivElement> {
withToolbar?: boolean;
/** Set heading level to the chip item label */
headingLevel?: 'h1' | 'h2' | 'h3' | 'h4' | 'h5' | 'h6';
/** Set number of chips to show before overflow */

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Maybe change this to say Set number of items to show before overflow since or number of chips\chip groups to show before overflow

numChips?: number;
}

interface ChipGroupState {
Expand All @@ -39,9 +41,10 @@ export class ChipGroup extends React.Component<ChipGroupProps, ChipGroupState> {
className: '',
expandedText: 'Show Less',
collapsedText: '${remaining} more',
withToolbar: false,
defaultIsOpen: false
};
withToolbar: false,
defaultIsOpen: false,
numChips: 3
}

toggleCollapse = () => {
this.setState((prevState) => ({
Expand Down Expand Up @@ -84,9 +87,9 @@ interface InnerChipGroupProps extends ChipGroupProps {
}

const InnerChipGroup = (props: InnerChipGroupProps) => {
const { children, expandedText, isOpen, onToggleCollapse, collapsedText, withToolbar } = props;

const collapsedTextResult = fillTemplate(collapsedText as string, { remaining: React.Children.count(children) - 1 });
const { children, expandedText, isOpen, onToggleCollapse, collapsedText, withToolbar, numChips } = props;
const collapsedTextResult = fillTemplate(collapsedText as string, { remaining: React.Children.count(children) - numChips });
const mappedChildren = React.Children.map(children, (c) => {
const child = c as React.ReactElement<any>;
if (withToolbar) {
Expand All @@ -107,13 +110,13 @@ const InnerChipGroup = (props: InnerChipGroupProps) => {
) : (
<React.Fragment>
{mappedChildren.map((child, i) => {
if (i === 0) {
if (i < numChips) {
return child;
}
})}
</React.Fragment>
)}
{React.Children.count(children) > 1 && (
{React.Children.count(children) > numChips && (
<Chip isOverflowChip onClick={onToggleCollapse} component={withToolbar ? 'div' : 'li'}>
{isOpen ? expandedText : collapsedTextResult}
</Chip>
Expand Down
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ exports[`ChipGroup chip group default 1`] = `
defaultIsOpen={false}
expandedText="Show Less"
isOpen={false}
numChips={3}
onToggleCollapse={[Function]}
withToolbar={false}
>
Expand Down Expand Up @@ -38,6 +39,7 @@ exports[`ChipGroup chip group with toolbar 1`] = `
defaultIsOpen={false}
expandedText="Show Less"
isOpen={false}
numChips={3}
onToggleCollapse={[Function]}
withToolbar={true}
>
Expand Down
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -5362,18 +5362,35 @@ exports[`typeahead multi select renders selected successfully 1`] = `
</button>
</li>
<li
class="pf-c-chip pf-m-overflow"
class="pf-c-chip"
>
<span
class="pf-c-chip__text"
id="pf-random-id-1"
>
Mrs
</span>
<button
aria-label="close"
aria-label="Remove"
aria-labelledby="remove_pf-random-id-1 pf-random-id-1"
class="pf-c-button pf-m-plain"
id="remove_pf-random-id-1"
type="button"
>
<span
class="pf-c-chip__text"
<svg
aria-hidden="true"
fill="currentColor"
height="1em"
role="img"
style="vertical-align: -0.125em;"
viewBox="0 0 512 512"
width="1em"
>
1 more
</span>
<path
d="M256 8C119 8 8 119 8 256s111 248 248 248 248-111 248-248S393 8 256 8zm121.6 313.1c4.7 4.7 4.7 12.3 0 17L338 377.6c-4.7 4.7-12.3 4.7-17 0L256 312l-65.1 65.6c-4.7 4.7-12.3 4.7-17 0L134.4 338c-4.7-4.7-4.7-12.3 0-17l65.6-65-65.6-65.1c-4.7-4.7-4.7-12.3 0-17l39.6-39.6c4.7-4.7 12.3-4.7 17 0l65 65.7 65.1-65.6c4.7-4.7 12.3-4.7 17 0l39.6 39.6c4.7 4.7 4.7 12.3 0 17L312 256l65.6 65.1z"
transform=""
/>
</svg>
</button>
</li>
</ul>
Expand Down Expand Up @@ -5538,6 +5555,7 @@ exports[`typeahead multi select renders selected successfully 1`] = `
collapsedText="\${remaining} more"
defaultIsOpen={false}
expandedText="Show Less"
numChips={3}
withToolbar={false}
>
<ul
Expand All @@ -5549,6 +5567,7 @@ exports[`typeahead multi select renders selected successfully 1`] = `
defaultIsOpen={false}
expandedText="Show Less"
isOpen={false}
numChips={3}
onToggleCollapse={[Function]}
withToolbar={false}
>
Expand Down Expand Up @@ -5671,48 +5690,66 @@ exports[`typeahead multi select renders selected successfully 1`] = `
</Chip>
<Chip
className=""
closeBtnAriaLabel="close"
closeBtnAriaLabel="Remove"
component="li"
isOverflowChip={true}
isOverflowChip={false}
isReadOnly={false}
key=".$Mrs"
onClick={[Function]}
tooltipPosition="top"
>
<GenerateId
prefix="pf-random-id-"
>
<li
className="pf-c-chip pf-m-overflow"
className="pf-c-chip"
>
<span
className="pf-c-chip__text"
id="pf-random-id-1"
>
Mrs
</span>
<Component
aria-labelledby="remove_pf-random-id-1 pf-random-id-1"
ariaLabel="Remove"
id="remove_pf-random-id-1"
onClick={[Function]}
>
<Component
aria-label="close"
aria-label="Remove"
aria-labelledby="remove_pf-random-id-1 pf-random-id-1"
className=""
id="remove_pf-random-id-1"
onClick={[Function]}
variant="plain"
>
<ComponentWithOuia
component={[Function]}
componentProps={
Object {
"aria-label": "close",
"children": <span
className="pf-c-chip__text"
>
1 more
</span>,
"aria-label": "Remove",
"aria-labelledby": "remove_pf-random-id-1 pf-random-id-1",
"children": <TimesCircleIcon
aria-hidden="true"
color="currentColor"
noVerticalAlign={false}
size="sm"
title={null}
/>,
"className": "",
"id": "remove_pf-random-id-1",
"onClick": [Function],
"variant": "plain",
}
}
consumerContext={null}
>
<Button
aria-label="close"
aria-label="Remove"
aria-labelledby="remove_pf-random-id-1 pf-random-id-1"
className=""
id="remove_pf-random-id-1"
onClick={[Function]}
ouiaContext={
Object {
Expand All @@ -5724,18 +5761,42 @@ exports[`typeahead multi select renders selected successfully 1`] = `
>
<button
aria-disabled={null}
aria-label="close"
aria-label="Remove"
aria-labelledby="remove_pf-random-id-1 pf-random-id-1"
className="pf-c-button pf-m-plain"
disabled={false}
id="remove_pf-random-id-1"
onClick={[Function]}
tabIndex={null}
type="button"
>
<span
className="pf-c-chip__text"
<TimesCircleIcon
aria-hidden="true"
color="currentColor"
noVerticalAlign={false}
size="sm"
title={null}
>
1 more
</span>
<svg
aria-hidden="true"
aria-labelledby={null}
fill="currentColor"
height="1em"
role="img"
style={
Object {
"verticalAlign": "-0.125em",
}
}
viewBox="0 0 512 512"
width="1em"
>
<path
d="M256 8C119 8 8 119 8 256s111 248 248 248 248-111 248-248S393 8 256 8zm121.6 313.1c4.7 4.7 4.7 12.3 0 17L338 377.6c-4.7 4.7-12.3 4.7-17 0L256 312l-65.1 65.6c-4.7 4.7-12.3 4.7-17 0L134.4 338c-4.7-4.7-4.7-12.3 0-17l65.6-65-65.6-65.1c-4.7-4.7-4.7-12.3 0-17l39.6-39.6c4.7-4.7 12.3-4.7 17 0l65 65.7 65.1-65.6c4.7-4.7 12.3-4.7 17 0l39.6 39.6c4.7 4.7 4.7 12.3 0 17L312 256l65.6 65.1z"
transform=""
/>
</svg>
</TimesCircleIcon>
</button>
</Button>
</ComponentWithOuia>
Expand Down

Back | FazBrowse Home | New Git URL