Skip to content

Commit

Permalink
feat: wrap contextual help if primitive (#817)
Browse files Browse the repository at this point in the history
- Adds #733 
- If the `contextualHelp` prop is a primitive, wrap it in
`ContextualHelp` and `Content`

---------

Co-authored-by: Vlad Babich <[email protected]>
  • Loading branch information
wusteven815 and vbabich authored Sep 13, 2024
1 parent 0dcfe3a commit 7e51073
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions plugins/ui/src/js/src/widget/WidgetUtils.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import {
isCallableNode,
CALLABLE_KEY,
wrapTextChildren,
isPrimitive,
} from '../elements/utils/ElementUtils';
import HTMLElementView from '../elements/HTMLElementView';
import { isHTMLElementNode } from '../elements/utils/HTMLElementUtils';
Expand Down Expand Up @@ -160,14 +161,20 @@ export function getComponentForElement(element: ElementNode): React.ReactNode {
const Component = getComponentTypeForElement(newElement);

if (Component != null) {
const props =
const props = { ...newElement.props };
if (
shouldWrapTextChildren.has(newElement[ELEMENT_KEY]) &&
newElement.props?.children != null
? {
...newElement.props,
children: wrapTextChildren(newElement.props.children),
}
: newElement.props;
props?.children != null
) {
props.children = wrapTextChildren(props.children);
}
if (props?.contextualHelp != null && isPrimitive(props.contextualHelp)) {
props.contextualHelp = (
<ContextualHelp>
<Content>{props.contextualHelp}</Content>
</ContextualHelp>
);
}

return <Component {...props} />;
}
Expand Down

0 comments on commit 7e51073

Please sign in to comment.