Skip to content

Commit

Permalink
fix: form: add portal prop to tooltip to fix tooltip in modal (#424)
Browse files Browse the repository at this point in the history
* fix: form: add portal prop to tooltip to fix tooltip in modal

* chore: form: pass parent element to tooltip portal
  • Loading branch information
dkilgore-eightfold authored Oct 19, 2022
1 parent 079438b commit 5c6beed
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 4 deletions.
1 change: 1 addition & 0 deletions src/components/Form/Form.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1478,6 +1478,7 @@ const ModalForm: React.FC<ModalFormProps> = ({ visible, onCancel }) => {
name={'name'}
label={'Name'}
rules={[{ required: true }]}
tooltip={<span>A Tooltip!</span>}
>
<TextInput />
</Form.Item>
Expand Down
4 changes: 4 additions & 0 deletions src/components/Form/Form.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,10 @@ export interface FormItemLabelProps {
* Set sub label `htmlFor`
*/
htmlFor?: string;
/**
* The parent element ref.
*/
itemRef?: React.MutableRefObject<HTMLDivElement>;
/**
* Label text
*/
Expand Down
1 change: 1 addition & 0 deletions src/components/Form/FormItem/ItemHolder.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@ export default function ItemHolder(props: ItemHolderProps) {
>
<FormItemLabel
htmlFor={fieldId}
itemRef={itemRef}
required={isRequired}
requiredMark={requiredMark}
{...props}
Expand Down
13 changes: 9 additions & 4 deletions src/components/Form/FormItemLabel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,12 @@ function toTooltipProps(tooltip: LabelTooltipType): WrapperTooltipProps | null {
}

const FormItemLabel: React.FC<FormItemLabelProps & { required?: boolean }> = ({
label,
colon,
htmlFor,
labelCol,
itemRef,
label,
labelAlign,
colon,
labelCol,
required,
requiredMark,
tooltip,
Expand Down Expand Up @@ -98,7 +99,11 @@ const FormItemLabel: React.FC<FormItemLabelProps & { required?: boolean }> = ({
...restTooltipProps
} = tooltipProps;
const tooltipNode = (
<Tooltip {...restTooltipProps}>
<Tooltip
portal
portalRoot={itemRef?.current}
{...restTooltipProps}
>
{React.cloneElement(icon, {
className: styles.formItemTooltip,
title: '',
Expand Down

0 comments on commit 5c6beed

Please sign in to comment.