-
Notifications
You must be signed in to change notification settings - Fork 67
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3125959
commit 693d972
Showing
2 changed files
with
29 additions
and
3 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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 |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { LabelGroup as PFLabelGroup } from '@patternfly/react-core'; | ||
|
||
type LabelGroupWrapperState = { | ||
headingRef: { current: { offsetWidth: number; scrollWidth: number } }; | ||
}; | ||
|
||
// fix button without type when rendering "show more" in forms | ||
export class LabelGroupWrapper extends PFLabelGroup { | ||
// @ts-expect-error Type '(e: React.MouseEvent<HTMLButtonElement>) => void' is not assignable to type '() => void'. | ||
toggleCollapse = (event: React.MouseEvent<HTMLButtonElement>) => { | ||
// Label isOverflowLabel renders a button, but not button type=button, breaks forms | ||
event.preventDefault(); | ||
|
||
// original LabelGroup toggleCollapse, as of @patternfly/react-core 5.2.0, w/ ts fix | ||
this.setState((prevState) => { | ||
const obj = this as unknown as LabelGroupWrapperState; | ||
const currentRef = obj.headingRef.current; | ||
|
||
return { | ||
isOpen: !prevState.isOpen, | ||
isTooltipVisible: Boolean(currentRef && currentRef.offsetWidth < currentRef.scrollWidth), | ||
}; | ||
}); | ||
}; | ||
} |