From 43686b4d7b0dc902934107035d0c3b2eb79582bd Mon Sep 17 00:00:00 2001 From: mertsincan Date: Sat, 2 Apr 2022 12:20:08 +0100 Subject: [PATCH] Fixed #2360 - React 18 support for Tooltip --- components/lib/autocomplete/AutoComplete.js | 49 ++-- components/lib/button/Button.js | 44 +-- components/lib/calendar/Calendar.js | 34 +-- components/lib/checkbox/Checkbox.js | 45 +-- components/lib/chips/Chips.js | 35 +-- components/lib/colorpicker/ColorPicker.js | 47 ++-- components/lib/dropdown/Dropdown.js | 59 ++-- components/lib/inputmask/InputMask.js | 30 +- components/lib/inputnumber/InputNumber.js | 39 +-- components/lib/inputswitch/InputSwitch.js | 46 +--- components/lib/inputtext/InputText.js | 34 +-- components/lib/inputtextarea/InputTextarea.js | 32 +-- components/lib/listbox/ListBox.js | 46 +--- components/lib/multiselect/MultiSelect.js | 63 ++--- .../multistatecheckbox/MultiStateCheckbox.js | 47 +--- components/lib/password/Password.js | 29 +- components/lib/radiobutton/RadioButton.js | 44 +-- components/lib/rating/Rating.js | 38 +-- components/lib/selectbutton/SelectButton.js | 38 +-- components/lib/splitbutton/SplitButton.js | 57 ++-- components/lib/togglebutton/ToggleButton.js | 44 +-- components/lib/tooltip/Tooltip.js | 46 +--- .../lib/tristatecheckbox/TriStateCheckbox.js | 44 +-- components/lib/utils/DomHandler.js | 256 +++++++++--------- 24 files changed, 419 insertions(+), 827 deletions(-) diff --git a/components/lib/autocomplete/AutoComplete.js b/components/lib/autocomplete/AutoComplete.js index 3b58ad814b..57d31ef69b 100644 --- a/components/lib/autocomplete/AutoComplete.js +++ b/components/lib/autocomplete/AutoComplete.js @@ -1,12 +1,12 @@ import React, { forwardRef, memo, useEffect, useImperativeHandle, useRef, useState } from 'react'; import PrimeReact from '../api/Api'; -import { AutoCompletePanel } from './AutoCompletePanel'; -import { InputText } from '../inputtext/InputText'; import { Button } from '../button/Button'; -import { tip } from '../tooltip/Tooltip'; +import { useMountEffect, useOverlayListener, useUnmountEffect, useUpdateEffect } from '../hooks/Hooks'; +import { InputText } from '../inputtext/InputText'; import { OverlayService } from '../overlayservice/OverlayService'; -import { DomHandler, ObjectUtils, classNames, UniqueComponentId, ZIndexUtils, IconUtils } from '../utils/Utils'; -import { useMountEffect, useUpdateEffect, useUnmountEffect, useOverlayListener } from '../hooks/Hooks'; +import { Tooltip } from '../tooltip/Tooltip'; +import { classNames, DomHandler, IconUtils, ObjectUtils, UniqueComponentId, ZIndexUtils } from '../utils/Utils'; +import { AutoCompletePanel } from './AutoCompletePanel'; export const AutoComplete = memo(forwardRef((props, ref) => { const [idState, setIdState] = useState(props.id); @@ -15,7 +15,6 @@ export const AutoComplete = memo(forwardRef((props, ref) => { const [overlayVisibleState, setOverlayVisibleState] = useState(false); const elementRef = useRef(null); const overlayRef = useRef(null); - const tooltipRef = useRef(null); const inputRef = useRef(props.inputRef); const multiContainerRef = useRef(null); const virtualScrollerRef = useRef(null); @@ -414,19 +413,6 @@ export const AutoComplete = memo(forwardRef((props, ref) => { ObjectUtils.combinedRefs(inputRef, props.inputRef); }, [inputRef, props.inputRef]); - useEffect(() => { - if (tooltipRef.current) { - tooltipRef.current.update({ content: props.tooltip, ...(props.tooltipOptions || {}) }); - } - else if (props.tooltip) { - tooltipRef.current = tip({ - target: elementRef.current, - content: props.tooltip, - options: props.tooltipOptions - }); - } - }, [props.tooltip, props.tooltipOptions]); - useMountEffect(() => { if (!idState) { setIdState(UniqueComponentId()); @@ -455,11 +441,6 @@ export const AutoComplete = memo(forwardRef((props, ref) => { clearTimeout(timeout.current); } - if (tooltipRef.current) { - tooltipRef.current.destroy(); - tooltipRef.current = null; - } - ZIndexUtils.clear(overlayRef.current); }); @@ -555,6 +536,7 @@ export const AutoComplete = memo(forwardRef((props, ref) => { } const listId = idState + '_list'; + const hasTooltip = ObjectUtils.isNotEmpty(props.tooltip); const className = classNames('p-autocomplete p-component p-inputwrapper', { 'p-autocomplete-dd': props.dropdown, 'p-autocomplete-multiple': props.multiple, @@ -566,14 +548,17 @@ export const AutoComplete = memo(forwardRef((props, ref) => { const dropdown = createDropdown(); return ( - - {input} - {loader} - {dropdown} - - + <> + + {input} + {loader} + {dropdown} + + + {hasTooltip && } + ) })); diff --git a/components/lib/button/Button.js b/components/lib/button/Button.js index 0de930ccbf..7add632609 100644 --- a/components/lib/button/Button.js +++ b/components/lib/button/Button.js @@ -1,37 +1,15 @@ import React, { forwardRef, memo, useEffect, useRef } from 'react'; -import { tip } from '../tooltip/Tooltip'; import { Ripple } from '../ripple/Ripple'; -import { ObjectUtils, classNames, IconUtils } from '../utils/Utils'; -import { useUnmountEffect } from '../hooks/Hooks'; +import { Tooltip } from '../tooltip/Tooltip'; +import { classNames, IconUtils, ObjectUtils } from '../utils/Utils'; export const Button = memo(forwardRef((props, ref) => { const elementRef = useRef(ref); - const tooltipRef = useRef(null); useEffect(() => { ObjectUtils.combinedRefs(elementRef, ref); }, [elementRef, ref]); - useEffect(() => { - if (tooltipRef.current) { - tooltipRef.current.update({ content: props.tooltip, ...(props.tooltipOptions || {}) }); - } - else if (props.tooltip) { - tooltipRef.current = tip({ - target: elementRef.current, - content: props.tooltip, - options: props.tooltipOptions - }); - } - }, [props.tooltip, props.tooltipOptions]); - - useUnmountEffect(() => { - if (tooltipRef.current) { - tooltipRef.current.destroy(); - tooltipRef.current = null; - } - }); - const createIcon = () => { const icon = props.loading ? props.loadingIcon : props.icon; const className = classNames('p-button-icon p-c', { @@ -60,6 +38,7 @@ export const Button = memo(forwardRef((props, ref) => { return null; } + const hasTooltip = ObjectUtils.isNotEmpty(props.tooltip); const disabled = props.disabled || props.loading; const buttonProps = ObjectUtils.findDiffKeys(props, Button.defaultProps); const className = classNames('p-button p-component', props.className, { @@ -76,13 +55,16 @@ export const Button = memo(forwardRef((props, ref) => { const badge = createBadge(); return ( - + <> + + {hasTooltip && } + ) })); diff --git a/components/lib/calendar/Calendar.js b/components/lib/calendar/Calendar.js index 46fd2fc8d4..36ad317e70 100644 --- a/components/lib/calendar/Calendar.js +++ b/components/lib/calendar/Calendar.js @@ -1,13 +1,12 @@ import React, { forwardRef, memo, useEffect, useImperativeHandle, useRef, useState } from 'react'; import PrimeReact, { localeOption, localeOptions } from '../api/Api'; -import { CalendarPanel } from './CalendarPanel'; -import { InputText } from '../inputtext/InputText'; import { Button } from '../button/Button'; -import { tip } from '../tooltip/Tooltip'; -import { Ripple } from '../ripple/Ripple'; +import { useMountEffect, useOverlayListener, usePrevious, useUnmountEffect, useUpdateEffect } from '../hooks/Hooks'; +import { InputText } from '../inputtext/InputText'; import { OverlayService } from '../overlayservice/OverlayService'; -import { DomHandler, ObjectUtils, classNames, mask, ZIndexUtils } from '../utils/Utils'; -import { useMountEffect, useUnmountEffect, useUpdateEffect, useOverlayListener, usePrevious } from '../hooks/Hooks'; +import { Ripple } from '../ripple/Ripple'; +import { classNames, DomHandler, mask, ObjectUtils, ZIndexUtils } from '../utils/Utils'; +import { CalendarPanel } from './CalendarPanel'; export const Calendar = memo(forwardRef((props, ref) => { const [focusedState, setFocusedState] = useState(false); @@ -16,7 +15,6 @@ export const Calendar = memo(forwardRef((props, ref) => { const elementRef = useRef(null); const overlayRef = useRef(null); const inputRef = useRef(props.inputRef); - const tooltipRef = useRef(null); const navigation = useRef(null); const ignoreFocusFunctionality = useRef(false); const isKeydown = useRef(false); @@ -2192,19 +2190,6 @@ export const Calendar = memo(forwardRef((props, ref) => { ObjectUtils.combinedRefs(inputRef, props.inputRef); }, [inputRef, props.inputRef]); - useEffect(() => { - if (tooltipRef.current) { - tooltipRef.current.update({ content: props.tooltip, ...(props.tooltipOptions || {}) }); - } - else if (props.tooltip) { - tooltipRef.current = tip({ - target: inputRef.current, - content: props.tooltip, - options: props.tooltipOptions - }); - } - }, [props.tooltip, props.tooltipOptions]); - useMountEffect(() => { let viewDate = getViewDate(props.viewDate); validateDate(viewDate); @@ -2270,11 +2255,6 @@ export const Calendar = memo(forwardRef((props, ref) => { touchUIMask.current = null; } - if (tooltipRef.current) { - tooltipRef.current.destroy(); - tooltipRef.current = null; - } - ZIndexUtils.clear(overlayRef.current); }); @@ -2746,7 +2726,8 @@ export const Calendar = memo(forwardRef((props, ref) => { return ( + onInput={onUserInput} onFocus={onInputFocus} onBlur={onInputBlur} onKeyDown={onInputKeyDown} aria-labelledby={props.ariaLabelledBy} inputMode={props.inputMode} + tooltip={props.tooltip} tooltipOptions={props.tooltipOptions} /> ) } @@ -2813,6 +2794,7 @@ export const Calendar = memo(forwardRef((props, ref) => { return null; } + const hasTooltip = ObjectUtils.isNotEmpty(props.tooltip); const className = classNames('p-calendar p-component p-inputwrapper', props.className, { [`p-calendar-w-btn p-calendar-w-btn-${props.iconPos}`]: props.showIcon, 'p-calendar-disabled': props.disabled, diff --git a/components/lib/checkbox/Checkbox.js b/components/lib/checkbox/Checkbox.js index d1c0417dd0..009f4c7778 100644 --- a/components/lib/checkbox/Checkbox.js +++ b/components/lib/checkbox/Checkbox.js @@ -1,13 +1,12 @@ import React, { forwardRef, memo, useEffect, useRef, useState } from 'react'; -import { tip } from '../tooltip/Tooltip'; +import { useUpdateEffect } from '../hooks/Hooks'; +import { Tooltip } from '../tooltip/Tooltip'; import { classNames, IconUtils, ObjectUtils } from '../utils/Utils'; -import { useUpdateEffect, useUnmountEffect } from '../hooks/Hooks'; export const Checkbox = memo(forwardRef((props, ref) => { const [focusedState, setFocusedState] = useState(false); const elementRef = useRef(null); const inputRef = useRef(props.inputRef); - const tooltipRef = useRef(null); const onClick = (event) => { if (!props.disabled && !props.readOnly && props.onChange) { @@ -59,31 +58,12 @@ export const Checkbox = memo(forwardRef((props, ref) => { ObjectUtils.combinedRefs(inputRef, props.inputRef); }, [inputRef, props.inputRef]); - useEffect(() => { - if (tooltipRef.current) { - tooltipRef.current.update({ content: props.tooltip, ...(props.tooltipOptions || {}) }); - } - else if (props.tooltip) { - tooltipRef.current = tip({ - target: elementRef.current, - content: props.tooltip, - options: props.tooltipOptions - }); - } - }, [props.tooltip, props.tooltipOptions]); - useUpdateEffect(() => { inputRef.current.checked = isChecked(); }, [props.checked, props.trueValue]); - useUnmountEffect(() => { - if (tooltipRef.current) { - tooltipRef.current.destroy(); - tooltipRef.current = null; - } - }); - const checked = isChecked(); + const hasTooltip = ObjectUtils.isNotEmpty(props.tooltip); const className = classNames('p-checkbox p-component', { 'p-checkbox-checked': checked, 'p-checkbox-disabled': props.disabled, @@ -97,15 +77,18 @@ export const Checkbox = memo(forwardRef((props, ref) => { const icon = IconUtils.getJSXIcon(checked && props.icon, { className: 'p-checkbox-icon p-c' }, { props, checked }); return ( -
-
- -
-
- {icon} + <> +
+
+ +
+
+ {icon} +
-
+ {hasTooltip && } + ) })); diff --git a/components/lib/chips/Chips.js b/components/lib/chips/Chips.js index fdce438912..441e890198 100644 --- a/components/lib/chips/Chips.js +++ b/components/lib/chips/Chips.js @@ -1,14 +1,12 @@ import React, { forwardRef, memo, useEffect, useMemo, useRef, useState } from 'react'; -import { tip } from '../tooltip/Tooltip'; +import { Tooltip } from '../tooltip/Tooltip'; import { classNames, ObjectUtils } from '../utils/Utils'; -import { useUnmountEffect } from '../hooks/Hooks'; export const Chips = memo(forwardRef((props, ref) => { const [focusedState, setFocusedState] = useState(false); const elementRef = useRef(null); const listRef = useRef(null); const inputRef = useRef(props.inputRef); - const tooltipRef = useRef(null); const removeItem = (event, index) => { if (props.disabled && props.readOnly) { @@ -157,27 +155,6 @@ export const Chips = memo(forwardRef((props, ref) => { ObjectUtils.combinedRefs(inputRef, props.inputRef); }, [inputRef, props.inputRef]); - useEffect(() => { - if (tooltipRef.current) { - tooltipRef.current.update({ content: props.tooltip, ...(props.tooltipOptions || {}) }); - } - else if (props.tooltip) { - tooltipRef.current = tip({ - target: inputRef.current, - targetContainer: listRef.current, - content: props.tooltip, - options: props.tooltipOptions - }); - } - }, [props.tooltip, props.tooltipOptions]); - - useUnmountEffect(() => { - if (tooltipRef.current) { - tooltipRef.current.destroy(); - tooltipRef.current = null; - } - }); - const createRemoveIcon = (value, index) => { if (!props.disabled && !props.readOnly && isRemovable(value, index)) { return removeItem(event, index)}> @@ -229,6 +206,7 @@ export const Chips = memo(forwardRef((props, ref) => { ) } + const hasTooltip = ObjectUtils.isNotEmpty(props.tooltip); const className = classNames('p-chips p-component p-inputwrapper', { 'p-inputwrapper-filled': isFilled, 'p-inputwrapper-focus': focusedState @@ -236,9 +214,12 @@ export const Chips = memo(forwardRef((props, ref) => { const list = createList(); return ( -
- {list} -
+ <> +
+ {list} +
+ {hasTooltip && } + ) })); diff --git a/components/lib/colorpicker/ColorPicker.js b/components/lib/colorpicker/ColorPicker.js index 5fcc4969a6..a2d06bd52a 100644 --- a/components/lib/colorpicker/ColorPicker.js +++ b/components/lib/colorpicker/ColorPicker.js @@ -1,17 +1,16 @@ import React, { forwardRef, memo, useEffect, useRef, useState } from 'react'; import PrimeReact from '../api/Api'; -import { ColorPickerPanel } from './ColorPickerPanel'; -import { tip } from '../tooltip/Tooltip'; +import { useEventListener, useMountEffect, useOverlayListener, useUnmountEffect, useUpdateEffect } from '../hooks/Hooks'; import { OverlayService } from '../overlayservice/OverlayService'; -import { DomHandler, ObjectUtils, classNames, ZIndexUtils } from '../utils/Utils'; -import { useUnmountEffect, useEventListener, useOverlayListener, useUpdateEffect, useMountEffect } from '../hooks/Hooks'; +import { Tooltip } from '../tooltip/Tooltip'; +import { classNames, DomHandler, ObjectUtils, ZIndexUtils } from '../utils/Utils'; +import { ColorPickerPanel } from './ColorPickerPanel'; export const ColorPicker = memo(forwardRef((props, ref) => { const [overlayVisibleState, setOverlayVisibleState] = useState(false); const elementRef = useRef(null); const overlayRef = useRef(null); const inputRef = useRef(props.inputRef); - const tooltipRef = useRef(null); const colorSelectorRef = useRef(null); const colorHandleRef = useRef(null); const hueHandleRef = useRef(null); @@ -442,19 +441,6 @@ export const ColorPicker = memo(forwardRef((props, ref) => { ObjectUtils.combinedRefs(inputRef, props.inputRef); }, [inputRef, props.inputRef]); - useEffect(() => { - if (tooltipRef.current) { - tooltipRef.current.update({ content: props.tooltip, ...(props.tooltipOptions || {}) }); - } - else if (props.tooltip) { - tooltipRef.current = tip({ - target: elementRef.current, - content: props.tooltip, - options: props.tooltipOptions - }); - } - }, [props.tooltip, props.tooltipOptions]); - useMountEffect(() => { updateHSBValue(props.value); updateUI(); @@ -471,11 +457,6 @@ export const ColorPicker = memo(forwardRef((props, ref) => { }); useUnmountEffect(() => { - if (tooltipRef.current) { - tooltipRef.current.destroy(); - tooltipRef.current = null; - } - ZIndexUtils.clear(overlayRef.current); }); @@ -528,6 +509,7 @@ export const ColorPicker = memo(forwardRef((props, ref) => { return null; } + const hasTooltip = ObjectUtils.isNotEmpty(props.tooltip); const className = classNames('p-colorpicker p-component', { 'p-colorpicker-overlay': !props.inline }, props.className); @@ -535,14 +517,17 @@ export const ColorPicker = memo(forwardRef((props, ref) => { const input = createInput(); return ( -
- {input} - - {content} - -
+ <> +
+ {input} + + {content} + +
+ {hasTooltip && } + ) })); diff --git a/components/lib/dropdown/Dropdown.js b/components/lib/dropdown/Dropdown.js index 91064636bb..51241b6778 100644 --- a/components/lib/dropdown/Dropdown.js +++ b/components/lib/dropdown/Dropdown.js @@ -1,10 +1,10 @@ import React, { forwardRef, memo, useEffect, useRef, useState } from 'react'; import PrimeReact, { FilterService } from '../api/Api'; -import { DropdownPanel } from './DropdownPanel'; -import { tip } from '../tooltip/Tooltip'; +import { useMountEffect, useOverlayListener, useUnmountEffect, useUpdateEffect } from '../hooks/Hooks'; import { OverlayService } from '../overlayservice/OverlayService'; -import { DomHandler, ObjectUtils, classNames, ZIndexUtils } from '../utils/Utils'; -import { useMountEffect, useUpdateEffect, useUnmountEffect, useOverlayListener } from '../hooks/Hooks'; +import { Tooltip } from '../tooltip/Tooltip'; +import { classNames, DomHandler, ObjectUtils, ZIndexUtils } from '../utils/Utils'; +import { DropdownPanel } from './DropdownPanel'; export const Dropdown = memo(forwardRef((props, ref) => { const [filterState, setFilterState] = useState(''); @@ -13,7 +13,6 @@ export const Dropdown = memo(forwardRef((props, ref) => { const elementRef = useRef(null); const overlayRef = useRef(null); const inputRef = useRef(props.inputRef); - const tooltipRef = useRef(null); const focusInputRef = useRef(null); const searchTimeout = useRef(null); const searchValue = useRef(null); @@ -553,19 +552,6 @@ export const Dropdown = memo(forwardRef((props, ref) => { ObjectUtils.combinedRefs(inputRef, props.inputRef); }, [inputRef, props.inputRef]); - useEffect(() => { - if (tooltipRef.current) { - tooltipRef.current.update({ content: props.tooltip, ...(props.tooltipOptions || {}) }); - } - else if (props.tooltip) { - tooltipRef.current = tip({ - target: elementRef.current, - content: props.tooltip, - options: props.tooltipOptions - }); - } - }, [props.tooltip, props.tooltipOptions]); - useMountEffect(() => { if (props.autoFocus && focusInputRef.current) { focusInputRef.current.focus(); @@ -597,11 +583,6 @@ export const Dropdown = memo(forwardRef((props, ref) => { useUnmountEffect(() => { ZIndexUtils.clear(overlayRef.current); - - if (tooltipRef.current) { - tooltipRef.current.destroy(); - tooltipRef.current = null; - } }); const createHiddenSelect = () => { @@ -673,6 +654,7 @@ export const Dropdown = memo(forwardRef((props, ref) => { const visibleOptions = getVisibleOptions(); const selectedOption = getSelectedOption(); + const hasTooltip = ObjectUtils.isNotEmpty(props.tooltip); const className = classNames('p-dropdown p-component p-inputwrapper', { 'p-disabled': props.disabled, 'p-focus': focusedState, @@ -687,20 +669,23 @@ export const Dropdown = memo(forwardRef((props, ref) => { const clearIcon = createClearIcon(); return ( -
- {keyboardHelper} - {hiddenSelect} - {labelElement} - {clearIcon} - {dropdownIcon} - -
+ <> +
+ {keyboardHelper} + {hiddenSelect} + {labelElement} + {clearIcon} + {dropdownIcon} + +
+ {hasTooltip && } + ) })); diff --git a/components/lib/inputmask/InputMask.js b/components/lib/inputmask/InputMask.js index 02a7149788..e14e992efb 100644 --- a/components/lib/inputmask/InputMask.js +++ b/components/lib/inputmask/InputMask.js @@ -1,12 +1,10 @@ import React, { forwardRef, memo, useCallback, useEffect, useRef } from 'react'; +import { useMountEffect, useUpdateEffect } from '../hooks/Hooks'; import { InputText } from '../inputtext/InputText'; -import { tip } from '../tooltip/Tooltip'; -import { DomHandler, classNames, ObjectUtils } from '../utils/Utils'; -import { useMountEffect, useUnmountEffect, useUpdateEffect } from '../hooks/Hooks'; +import { classNames, DomHandler, ObjectUtils } from '../utils/Utils'; export const InputMask = memo(forwardRef((props, ref) => { const elementRef = useRef(null); - const tooltipRef = useRef(null); const firstNonMaskPos = useRef(null); const lastRequiredNonMaskPos = useRef(0); const tests = useRef([]); @@ -510,19 +508,6 @@ export const InputMask = memo(forwardRef((props, ref) => { ObjectUtils.combinedRefs(elementRef, props.inputRef); }, [elementRef, props.inputRef]); - useEffect(() => { - if (tooltipRef.current) { - tooltipRef.current.update({ content: props.tooltip, ...(props.tooltipOptions || {}) }); - } - else if (props.tooltip) { - tooltipRef.current = tip({ - target: elementRef.current, - content: props.tooltip, - options: props.tooltipOptions - }); - } - }, [props.tooltip, props.tooltipOptions]); - useMountEffect(() => { init(); updateValue(); @@ -540,20 +525,13 @@ export const InputMask = memo(forwardRef((props, ref) => { } }, [isValueUpdated]); - useUnmountEffect(() => { - if (tooltipRef.current) { - tooltipRef.current.destroy(); - tooltipRef.current = null; - } - }); - const className = classNames('p-inputmask', props.className); return ( + onFocus={onFocus} onBlur={onBlur} onKeyDown={onKeyDown} onKeyPress={onKeyPress} onInput={onInput} onPaste={handleInputChange} + required={props.required} aria-labelledby={props.ariaLabelledBy} tooltip={props.tooltip} tooltipOptions={props.tooltipOptions} /> ) })); diff --git a/components/lib/inputnumber/InputNumber.js b/components/lib/inputnumber/InputNumber.js index 688d8cf56a..bc99fddc1f 100644 --- a/components/lib/inputnumber/InputNumber.js +++ b/components/lib/inputnumber/InputNumber.js @@ -1,15 +1,14 @@ import React, { forwardRef, memo, useEffect, useImperativeHandle, useRef, useState } from 'react'; -import { tip } from '../tooltip/Tooltip'; -import { Ripple } from '../ripple/Ripple'; +import { useMountEffect, useUpdateEffect } from '../hooks/Hooks'; import { InputText } from '../inputtext/InputText'; +import { Ripple } from '../ripple/Ripple'; +import { Tooltip } from '../tooltip/Tooltip'; import { classNames, ObjectUtils } from '../utils/Utils'; -import { useMountEffect, useUpdateEffect, useUnmountEffect } from '../hooks/Hooks'; export const InputNumber = memo(forwardRef((props, ref) => { const [focusedState, setFocusedState] = useState(false); const elementRef = useRef(null); const inputRef = useRef(null); - const tooltipRef = useRef(null); const timer = useRef(null); const lastValue = useRef(null); @@ -911,19 +910,6 @@ export const InputNumber = memo(forwardRef((props, ref) => { ObjectUtils.combinedRefs(inputRef, props.inputRef); }, [inputRef, props.inputRef]); - useEffect(() => { - if (tooltipRef.current) { - tooltipRef.current.update({ content: props.tooltip, ...(props.tooltipOptions || {}) }); - } - else if (props.tooltip) { - tooltipRef.current = tip({ - target: elementRef.current, - content: props.tooltip, - options: props.tooltipOptions - }); - } - }, [props.tooltip, props.tooltipOptions]); - useMountEffect(() => { constructParser(); @@ -942,13 +928,6 @@ export const InputNumber = memo(forwardRef((props, ref) => { changeValue(); }, [props.value]); - useUnmountEffect(() => { - if (tooltipRef.current) { - tooltipRef.current.destroy(); - tooltipRef.current = null; - } - }); - const createInputElement = () => { const className = classNames('p-inputnumber-input', props.inputClassName); const valueToRender = formattedValue(props.value); @@ -1015,6 +994,7 @@ export const InputNumber = memo(forwardRef((props, ref) => { ) } + const hasTooltip = ObjectUtils.isNotEmpty(props.tooltip); const className = classNames('p-inputnumber p-component p-inputwrapper', { 'p-inputwrapper-filled': props.value != null && props.value.toString().length > 0, 'p-inputwrapper-focus': focusedState, @@ -1026,10 +1006,13 @@ export const InputNumber = memo(forwardRef((props, ref) => { const buttonGroup = createButtonGroup(); return ( - - {inputElement} - {buttonGroup} - + <> + + {inputElement} + {buttonGroup} + + {hasTooltip && } + ) })); diff --git a/components/lib/inputswitch/InputSwitch.js b/components/lib/inputswitch/InputSwitch.js index 132a11c94c..c9ce6057cb 100644 --- a/components/lib/inputswitch/InputSwitch.js +++ b/components/lib/inputswitch/InputSwitch.js @@ -1,13 +1,11 @@ import React, { forwardRef, memo, useEffect, useRef, useState } from 'react'; -import { tip } from '../tooltip/Tooltip'; -import { ObjectUtils, classNames } from '../utils/Utils'; -import { useUnmountEffect } from '../hooks/Hooks'; +import { Tooltip } from '../tooltip/Tooltip'; +import { classNames, ObjectUtils } from '../utils/Utils'; export const InputSwitch = memo(forwardRef((props, ref) => { const [focusedState, setFocusedState] = useState(false); const elementRef = useRef(null); const inputRef = useRef(props.inputRef); - const tooltipRef = useRef(null); const checked = props.checked === props.trueValue; const onClick = (event) => { @@ -59,26 +57,7 @@ export const InputSwitch = memo(forwardRef((props, ref) => { ObjectUtils.combinedRefs(inputRef, props.inputRef); }, [inputRef, props.inputRef]); - useEffect(() => { - if (tooltipRef.current) { - tooltipRef.current.update({ content: props.tooltip, ...(props.tooltipOptions || {}) }); - } - else if (props.tooltip) { - tooltipRef.current = tip({ - target: elementRef.current, - content: props.tooltip, - options: props.tooltipOptions - }); - } - }, [props.tooltip, props.tooltipOptions]); - - useUnmountEffect(() => { - if (tooltipRef.current) { - tooltipRef.current.destroy(); - tooltipRef.current = null; - } - }); - + const hasTooltip = ObjectUtils.isNotEmpty(props.tooltip); const className = classNames('p-inputswitch p-component', { 'p-inputswitch-checked': checked, 'p-disabled': props.disabled, @@ -88,15 +67,18 @@ export const InputSwitch = memo(forwardRef((props, ref) => { const inputSwitchProps = ObjectUtils.findDiffKeys(props, InputSwitch.defaultProps); return ( -