From 538c2d62100cbe019e6df5e1ff62f2e99ca926c8 Mon Sep 17 00:00:00 2001 From: erkanercan Date: Tue, 22 Nov 2022 20:35:47 +0300 Subject: [PATCH 1/5] fix: forward given role to chip component #8353 --- .../react-core/src/components/Chip/Chip.tsx | 2 + .../components/Chip/__tests__/Chip.test.tsx | 9 ++++ .../__snapshots__/Chip.test.tsx.snap | 44 +++++++++++++++++++ 3 files changed, 55 insertions(+) diff --git a/packages/react-core/src/components/Chip/Chip.tsx b/packages/react-core/src/components/Chip/Chip.tsx index 55d8b867150..e41c8cde297 100644 --- a/packages/react-core/src/components/Chip/Chip.tsx +++ b/packages/react-core/src/components/Chip/Chip.tsx @@ -95,6 +95,7 @@ export class Chip extends React.Component { className={css(styles.chip, styles.modifiers.overflow, className)} {...(this.props.component === 'button' ? { type: 'button' } : {})} {...getOUIAProps('OverflowChip', ouiaId !== undefined ? ouiaId : this.state.ouiaStateId)} + {...(this.props.role && { role: this.props.role })} > {children} @@ -112,6 +113,7 @@ export class Chip extends React.Component { className={css(styles.chip, className)} {...(this.state.isTooltipVisible && { tabIndex: 0 })} {...getOUIAProps(Chip.displayName, ouiaId !== undefined ? ouiaId : this.state.ouiaStateId)} + {...(this.props.role && { role: this.props.role })} > {children} diff --git a/packages/react-core/src/components/Chip/__tests__/Chip.test.tsx b/packages/react-core/src/components/Chip/__tests__/Chip.test.tsx index df9dde4fc45..56e178e1b4b 100644 --- a/packages/react-core/src/components/Chip/__tests__/Chip.test.tsx +++ b/packages/react-core/src/components/Chip/__tests__/Chip.test.tsx @@ -47,4 +47,13 @@ describe('Chip', () => { ); expect(asFragment()).toMatchSnapshot(); }); + + test("with role='gridcell'", () => { + const { asFragment } = render( + + I'm a roled chip + + ); + expect(asFragment()).toMatchSnapshot(); + }); }); diff --git a/packages/react-core/src/components/Chip/__tests__/__snapshots__/Chip.test.tsx.snap b/packages/react-core/src/components/Chip/__tests__/__snapshots__/Chip.test.tsx.snap index 3cf7ee49a22..c60ae8e8868 100644 --- a/packages/react-core/src/components/Chip/__tests__/__snapshots__/Chip.test.tsx.snap +++ b/packages/react-core/src/components/Chip/__tests__/__snapshots__/Chip.test.tsx.snap @@ -164,3 +164,47 @@ exports[`Chip readonly 1`] = ` `; + +exports[`Chip with role='gridcell' 1`] = ` + +
+ + I'm a roled chip + + +
+
+`; From 628237a7c0cd1340334d6c6e59371ee21c62228a Mon Sep 17 00:00:00 2001 From: erkanercan Date: Wed, 14 Dec 2022 22:58:45 +0300 Subject: [PATCH 2/5] fix: spread props to all chips https://github.com/patternfly/patternfly-react/pull/8383#issuecomment-1329742421 --- .../react-core/src/components/Chip/Chip.tsx | 4 +-- .../__snapshots__/Chip.test.tsx.snap | 33 +++++++++++++++---- .../__snapshots__/ChipGroup.test.tsx.snap | 20 ++++++++--- .../__snapshots__/Select.test.tsx.snap | 10 ++++-- .../__snapshots__/Toolbar.test.tsx.snap | 10 ++++-- 5 files changed, 61 insertions(+), 16 deletions(-) diff --git a/packages/react-core/src/components/Chip/Chip.tsx b/packages/react-core/src/components/Chip/Chip.tsx index e41c8cde297..f2687bb10b0 100644 --- a/packages/react-core/src/components/Chip/Chip.tsx +++ b/packages/react-core/src/components/Chip/Chip.tsx @@ -95,7 +95,7 @@ export class Chip extends React.Component { className={css(styles.chip, styles.modifiers.overflow, className)} {...(this.props.component === 'button' ? { type: 'button' } : {})} {...getOUIAProps('OverflowChip', ouiaId !== undefined ? ouiaId : this.state.ouiaStateId)} - {...(this.props.role && { role: this.props.role })} + {...this.props} > {children} @@ -113,7 +113,7 @@ export class Chip extends React.Component { className={css(styles.chip, className)} {...(this.state.isTooltipVisible && { tabIndex: 0 })} {...getOUIAProps(Chip.displayName, ouiaId !== undefined ? ouiaId : this.state.ouiaStateId)} - {...(this.props.role && { role: this.props.role })} + {...this.props} > {children} diff --git a/packages/react-core/src/components/Chip/__tests__/__snapshots__/Chip.test.tsx.snap b/packages/react-core/src/components/Chip/__tests__/__snapshots__/Chip.test.tsx.snap index c60ae8e8868..bdab9b43aec 100644 --- a/packages/react-core/src/components/Chip/__tests__/__snapshots__/Chip.test.tsx.snap +++ b/packages/react-core/src/components/Chip/__tests__/__snapshots__/Chip.test.tsx.snap @@ -3,10 +3,14 @@ exports[`Chip closable 1`] = `
Date: Wed, 14 Dec 2022 23:02:27 +0300 Subject: [PATCH 3/5] fix: class overrides --- packages/react-core/src/components/Chip/Chip.tsx | 4 ++-- .../Chip/__tests__/__snapshots__/Chip.test.tsx.snap | 12 ++++++------ .../__tests__/__snapshots__/ChipGroup.test.tsx.snap | 8 ++++---- .../__tests__/__snapshots__/Select.test.tsx.snap | 4 ++-- .../__tests__/__snapshots__/Toolbar.test.tsx.snap | 4 ++-- 5 files changed, 16 insertions(+), 16 deletions(-) diff --git a/packages/react-core/src/components/Chip/Chip.tsx b/packages/react-core/src/components/Chip/Chip.tsx index f2687bb10b0..5e78950ca64 100644 --- a/packages/react-core/src/components/Chip/Chip.tsx +++ b/packages/react-core/src/components/Chip/Chip.tsx @@ -88,6 +88,7 @@ export class Chip extends React.Component { return ( { className={css(styles.chip, styles.modifiers.overflow, className)} {...(this.props.component === 'button' ? { type: 'button' } : {})} {...getOUIAProps('OverflowChip', ouiaId !== undefined ? ouiaId : this.state.ouiaStateId)} - {...this.props} > {children} @@ -107,13 +107,13 @@ export class Chip extends React.Component { const Component = component as any; return ( {children} diff --git a/packages/react-core/src/components/Chip/__tests__/__snapshots__/Chip.test.tsx.snap b/packages/react-core/src/components/Chip/__tests__/__snapshots__/Chip.test.tsx.snap index bdab9b43aec..097492464e9 100644 --- a/packages/react-core/src/components/Chip/__tests__/__snapshots__/Chip.test.tsx.snap +++ b/packages/react-core/src/components/Chip/__tests__/__snapshots__/Chip.test.tsx.snap @@ -3,7 +3,7 @@ exports[`Chip closable 1`] = `
Date: Sat, 7 Jan 2023 12:17:27 +0300 Subject: [PATCH 4/5] refactor: props spread at the end --- packages/react-core/src/components/Chip/Chip.tsx | 4 ++-- .../Chip/__tests__/__snapshots__/Chip.test.tsx.snap | 12 ++++++------ .../__tests__/__snapshots__/ChipGroup.test.tsx.snap | 8 ++++---- .../__tests__/__snapshots__/Select.test.tsx.snap | 4 ++-- .../__tests__/__snapshots__/Toolbar.test.tsx.snap | 4 ++-- 5 files changed, 16 insertions(+), 16 deletions(-) diff --git a/packages/react-core/src/components/Chip/Chip.tsx b/packages/react-core/src/components/Chip/Chip.tsx index 5e78950ca64..f2687bb10b0 100644 --- a/packages/react-core/src/components/Chip/Chip.tsx +++ b/packages/react-core/src/components/Chip/Chip.tsx @@ -88,7 +88,6 @@ export class Chip extends React.Component { return ( { className={css(styles.chip, styles.modifiers.overflow, className)} {...(this.props.component === 'button' ? { type: 'button' } : {})} {...getOUIAProps('OverflowChip', ouiaId !== undefined ? ouiaId : this.state.ouiaStateId)} + {...this.props} > {children} @@ -107,13 +107,13 @@ export class Chip extends React.Component { const Component = component as any; return ( {children} diff --git a/packages/react-core/src/components/Chip/__tests__/__snapshots__/Chip.test.tsx.snap b/packages/react-core/src/components/Chip/__tests__/__snapshots__/Chip.test.tsx.snap index 097492464e9..bdab9b43aec 100644 --- a/packages/react-core/src/components/Chip/__tests__/__snapshots__/Chip.test.tsx.snap +++ b/packages/react-core/src/components/Chip/__tests__/__snapshots__/Chip.test.tsx.snap @@ -3,7 +3,7 @@ exports[`Chip closable 1`] = `
Date: Mon, 9 Jan 2023 23:46:39 +0300 Subject: [PATCH 5/5] fix: props spreaded in a different way --- .../react-core/src/components/Chip/Chip.tsx | 8 +++---- .../__snapshots__/Chip.test.tsx.snap | 22 +++++-------------- .../__snapshots__/ChipGroup.test.tsx.snap | 16 ++++---------- .../__snapshots__/Select.test.tsx.snap | 8 ++----- .../__snapshots__/Toolbar.test.tsx.snap | 8 ++----- 5 files changed, 18 insertions(+), 44 deletions(-) diff --git a/packages/react-core/src/components/Chip/Chip.tsx b/packages/react-core/src/components/Chip/Chip.tsx index f2687bb10b0..ae95d143358 100644 --- a/packages/react-core/src/components/Chip/Chip.tsx +++ b/packages/react-core/src/components/Chip/Chip.tsx @@ -83,7 +83,7 @@ export class Chip extends React.Component { }); renderOverflowChip = () => { - const { children, className, onClick, ouiaId } = this.props; + const { children, className, onClick, ouiaId, ...props } = this.props; const Component = this.props.component as any; return ( { className={css(styles.chip, styles.modifiers.overflow, className)} {...(this.props.component === 'button' ? { type: 'button' } : {})} {...getOUIAProps('OverflowChip', ouiaId !== undefined ? ouiaId : this.state.ouiaStateId)} - {...this.props} + {...props} > {children} @@ -103,7 +103,7 @@ export class Chip extends React.Component { }; renderInnerChip(id: string) { - const { children, className, onClick, closeBtnAriaLabel, isReadOnly, component, ouiaId } = this.props; + const { children, className, onClick, closeBtnAriaLabel, isReadOnly, component, ouiaId, ...props } = this.props; const Component = component as any; return ( { className={css(styles.chip, className)} {...(this.state.isTooltipVisible && { tabIndex: 0 })} {...getOUIAProps(Chip.displayName, ouiaId !== undefined ? ouiaId : this.state.ouiaStateId)} - {...this.props} + {...props} > {children} diff --git a/packages/react-core/src/components/Chip/__tests__/__snapshots__/Chip.test.tsx.snap b/packages/react-core/src/components/Chip/__tests__/__snapshots__/Chip.test.tsx.snap index bdab9b43aec..bd90c6b3076 100644 --- a/packages/react-core/src/components/Chip/__tests__/__snapshots__/Chip.test.tsx.snap +++ b/packages/react-core/src/components/Chip/__tests__/__snapshots__/Chip.test.tsx.snap @@ -3,9 +3,7 @@ exports[`Chip closable 1`] = `