Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #2963: Allow access to ref #2970

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion components/lib/autocomplete/AutoComplete.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export const AutoComplete = React.memo(React.forwardRef((props, ref) => {
const [searchingState, setSearchingState] = React.useState(false);
const [focusedState, setFocusedState] = React.useState(false);
const [overlayVisibleState, setOverlayVisibleState] = React.useState(false);
const elementRef = React.useRef(null);
const elementRef = React.useRef(ref);
const overlayRef = React.useRef(null);
const inputRef = React.useRef(props.inputRef);
const multiContainerRef = React.useRef(null);
Expand Down Expand Up @@ -422,6 +422,10 @@ export const AutoComplete = React.memo(React.forwardRef((props, ref) => {
ObjectUtils.combinedRefs(inputRef, props.inputRef);
}, [inputRef, props.inputRef]);

React.useEffect(() => {
ObjectUtils.combinedRefs(elementRef, ref);
}, [elementRef, ref]);

useMountEffect(() => {
if (!idState) {
setIdState(UniqueComponentId());
Expand Down
6 changes: 5 additions & 1 deletion components/lib/calendar/Calendar.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export const Calendar = React.memo(React.forwardRef((props, ref) => {
const [focusedState, setFocusedState] = React.useState(false);
const [overlayVisibleState, setOverlayVisibleState] = React.useState(false);
const [viewDateState, setViewDateState] = React.useState(null);
const elementRef = React.useRef(null);
const elementRef = React.useRef(ref);
const overlayRef = React.useRef(null);
const inputRef = React.useRef(props.inputRef);
const navigation = React.useRef(null);
Expand Down Expand Up @@ -2380,6 +2380,10 @@ export const Calendar = React.memo(React.forwardRef((props, ref) => {
ObjectUtils.combinedRefs(inputRef, props.inputRef);
}, [inputRef, props.inputRef]);

React.useEffect(() => {
ObjectUtils.combinedRefs(elementRef, ref);
}, [elementRef, ref]);

useMountEffect(() => {
let viewDate = getViewDate(props.viewDate);
validateDate(viewDate);
Expand Down
6 changes: 5 additions & 1 deletion components/lib/captcha/Captcha.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { useMountEffect, useUnmountEffect } from '../hooks/Hooks';
import { ObjectUtils } from '../utils/Utils';

export const Captcha = React.memo(React.forwardRef((props, ref) => {
const elementRef = React.useRef(null);
const elementRef = React.useRef(ref);
const instance = React.useRef(null);
const recaptchaScript = React.useRef(null);
const isCaptchaLoaded = React.useRef(false);
Expand Down Expand Up @@ -85,6 +85,10 @@ export const Captcha = React.memo(React.forwardRef((props, ref) => {
getResponse
}));

React.useEffect(() => {
ObjectUtils.combinedRefs(elementRef, ref);
}, [elementRef, ref]);

const otherProps = ObjectUtils.findDiffKeys(props, Captcha.defaultProps);

return <div ref={elementRef} id={props.id} {...otherProps}></div>
Expand Down
6 changes: 5 additions & 1 deletion components/lib/carousel/Carousel.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export const Carousel = React.memo(React.forwardRef((props, ref) => {
const [numScrollState, setNumScrollState] = React.useState(props.numScroll);
const [totalShiftedItemsState, setTotalShiftedItemsState] = React.useState((props.page * props.numScroll) * -1);
const [pageState, setPageState] = React.useState(props.page);
const elementRef = React.useRef(null);
const elementRef = React.useRef(ref);
const itemsContainerRef = React.useRef(null);
const remainingItems = React.useRef(0);
const allowAutoplay = React.useRef(!!props.autoplayInterval);
Expand Down Expand Up @@ -382,6 +382,10 @@ export const Carousel = React.memo(React.forwardRef((props, ref) => {
stopAutoplay();
}
});

React.useEffect(() => {
ObjectUtils.combinedRefs(elementRef, ref);
}, [elementRef, ref]);

const createItems = () => {
if (props.value && props.value.length) {
Expand Down
6 changes: 5 additions & 1 deletion components/lib/cascadeselect/CascadeSelect.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { CascadeSelectSub } from './CascadeSelectSub';
export const CascadeSelect = React.memo(React.forwardRef((props, ref) => {
const [focusedState, setFocusedState] = React.useState(false);
const [overlayVisibleState, setOverlayVisibleState] = React.useState(false);
const elementRef = React.useRef(null);
const elementRef = React.useRef(ref);
const overlayRef = React.useRef(null);
const inputRef = React.useRef(null);
const labelRef = React.useRef(null);
Expand Down Expand Up @@ -186,6 +186,10 @@ export const CascadeSelect = React.memo(React.forwardRef((props, ref) => {
ObjectUtils.combinedRefs(inputRef, props.inputRef);
}, [inputRef, props.inputRef]);

React.useEffect(() => {
ObjectUtils.combinedRefs(elementRef, ref);
}, [elementRef, ref]);

useUpdateEffect(() => {
updateSelectionPath();
}, [props.value]);
Expand Down
6 changes: 5 additions & 1 deletion components/lib/checkbox/Checkbox.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { classNames, IconUtils, ObjectUtils } from '../utils/Utils';

export const Checkbox = React.memo(React.forwardRef((props, ref) => {
const [focusedState, setFocusedState] = React.useState(false);
const elementRef = React.useRef(null);
const elementRef = React.useRef(ref);
const inputRef = React.useRef(props.inputRef);

const onClick = (event) => {
Expand Down Expand Up @@ -49,6 +49,10 @@ export const Checkbox = React.memo(React.forwardRef((props, ref) => {
ObjectUtils.combinedRefs(inputRef, props.inputRef);
}, [inputRef, props.inputRef]);

React.useEffect(() => {
ObjectUtils.combinedRefs(elementRef, ref);
}, [elementRef, ref]);

useUpdateEffect(() => {
inputRef.current.checked = isChecked();
}, [props.checked, props.trueValue]);
Expand Down
6 changes: 5 additions & 1 deletion components/lib/chips/Chips.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { classNames, ObjectUtils } from '../utils/Utils';

export const Chips = React.memo(React.forwardRef((props, ref) => {
const [focusedState, setFocusedState] = React.useState(false);
const elementRef = React.useRef(null);
const elementRef = React.useRef(ref);
const listRef = React.useRef(null);
const inputRef = React.useRef(props.inputRef);

Expand Down Expand Up @@ -173,6 +173,10 @@ export const Chips = React.memo(React.forwardRef((props, ref) => {
ObjectUtils.combinedRefs(inputRef, props.inputRef);
}, [inputRef, props.inputRef]);

React.useEffect(() => {
ObjectUtils.combinedRefs(elementRef, ref);
}, [elementRef, ref]);

const createRemoveIcon = (value, index) => {
if (!props.disabled && !props.readOnly && isRemovable(value, index)) {
return <span className="p-chips-token-icon pi pi-times-circle" onClick={(event) => removeItem(event, index)}></span>
Expand Down
6 changes: 5 additions & 1 deletion components/lib/colorpicker/ColorPicker.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { ColorPickerPanel } from './ColorPickerPanel';

export const ColorPicker = React.memo(React.forwardRef((props, ref) => {
const [overlayVisibleState, setOverlayVisibleState] = React.useState(false);
const elementRef = React.useRef(null);
const elementRef = React.useRef(ref);
const overlayRef = React.useRef(null);
const inputRef = React.useRef(props.inputRef);
const colorSelectorRef = React.useRef(null);
Expand Down Expand Up @@ -441,6 +441,10 @@ export const ColorPicker = React.memo(React.forwardRef((props, ref) => {
ObjectUtils.combinedRefs(inputRef, props.inputRef);
}, [inputRef, props.inputRef]);

React.useEffect(() => {
ObjectUtils.combinedRefs(elementRef, ref);
}, [elementRef, ref]);

useMountEffect(() => {
updateHSBValue(props.value);
updateUI();
Expand Down
6 changes: 5 additions & 1 deletion components/lib/dropdown/Dropdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export const Dropdown = React.memo(React.forwardRef((props, ref) => {
const [filterState, setFilterState] = React.useState('');
const [focusedState, setFocusedState] = React.useState(false);
const [overlayVisibleState, setOverlayVisibleState] = React.useState(false);
const elementRef = React.useRef(null);
const elementRef = React.useRef(ref);
const overlayRef = React.useRef(null);
const inputRef = React.useRef(props.inputRef);
const focusInputRef = React.useRef(null);
Expand Down Expand Up @@ -546,6 +546,10 @@ export const Dropdown = React.memo(React.forwardRef((props, ref) => {
ObjectUtils.combinedRefs(inputRef, props.inputRef);
}, [inputRef, props.inputRef]);

React.useEffect(() => {
ObjectUtils.combinedRefs(elementRef, ref);
}, [elementRef, ref]);

useMountEffect(() => {
if (props.autoFocus && focusInputRef.current) {
focusInputRef.current.focus();
Expand Down
6 changes: 5 additions & 1 deletion components/lib/fullcalendar/FullCalendar.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { useMountEffect, usePrevious, useUnmountEffect, useUpdateEffect } from '
import { ObjectUtils } from '../utils/Utils';

export const FullCalendar = React.memo(React.forwardRef((props, ref) => {
const elementRef = React.useRef(null);
const elementRef = React.useRef(ref);
const config = React.useRef({});
const calendar = React.useRef(null);
const prevEvents = usePrevious(props.events);
Expand Down Expand Up @@ -66,6 +66,10 @@ export const FullCalendar = React.memo(React.forwardRef((props, ref) => {
}
});

React.useEffect(() => {
ObjectUtils.combinedRefs(elementRef, ref);
}, [elementRef, ref]);

const otherProps = ObjectUtils.findDiffKeys(props, FullCalendar.defaultProps);

return <div ref={elementRef} id={props.id} style={props.style} className={props.className} {...otherProps}></div>
Expand Down
6 changes: 5 additions & 1 deletion components/lib/galleria/Galleria.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export const Galleria = React.memo(React.forwardRef((props, ref) => {
const [numVisibleState, setNumVisibleState] = React.useState(props.numVisible);
const [slideShowActiveState, setSlideShowActiveState] = React.useState(false);
const [activeIndexState, setActiveIndexState] = React.useState(props.activeIndex);
const elementRef = React.useRef(null);
const elementRef = React.useRef(ref);
const previewContentRef = React.useRef(null);
const maskRef = React.useRef(null);
const activeItemIndex = props.onItemChange ? props.activeIndex : activeIndexState;
Expand Down Expand Up @@ -93,6 +93,10 @@ export const Galleria = React.memo(React.forwardRef((props, ref) => {
setNumVisibleState(props.numVisible);
}, [props.numVisible]);

React.useEffect(() => {
ObjectUtils.combinedRefs(elementRef, ref);
}, [elementRef, ref]);

useUnmountEffect(() => {
if (slideShowActiveState) {
stopSlideShow();
Expand Down
6 changes: 5 additions & 1 deletion components/lib/gmap/GMap.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { useMountEffect, useUpdateEffect } from '../hooks/Hooks';
import { ObjectUtils } from '../utils/Utils';

export const GMap = React.memo(React.forwardRef((props, ref) => {
const elementRef = React.useRef(null);
const elementRef = React.useRef(ref);
const map = React.useRef(null);
const prevOverlays = React.useRef(null);

Expand Down Expand Up @@ -110,6 +110,10 @@ export const GMap = React.memo(React.forwardRef((props, ref) => {
}
});

React.useEffect(() => {
ObjectUtils.combinedRefs(elementRef, ref);
}, [elementRef, ref]);

React.useImperativeHandle(ref, () => ({
getMap
}));
Expand Down
6 changes: 5 additions & 1 deletion components/lib/image/Image.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export const Image = React.memo(React.forwardRef((props, ref) => {
const [previewVisibleState, setPreviewVisibleState] = React.useState(false);
const [rotateState, setRotateState] = React.useState(0);
const [scaleState, setScaleState] = React.useState(1);
const elementRef = React.useRef(null);
const elementRef = React.useRef(ref);
const maskRef = React.useRef(null);
const previewRef = React.useRef(null);
const previewClick = React.useRef(false);
Expand Down Expand Up @@ -90,6 +90,10 @@ export const Image = React.memo(React.forwardRef((props, ref) => {
maskRef.current && ZIndexUtils.clear(maskRef.current);
});

React.useEffect(() => {
ObjectUtils.combinedRefs(elementRef, ref);
}, [elementRef, ref]);

const createPreview = () => {
if (props.preview) {
return (
Expand Down
6 changes: 5 additions & 1 deletion components/lib/inputnumber/InputNumber.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { classNames, DomHandler, ObjectUtils } from '../utils/Utils';

export const InputNumber = React.memo(React.forwardRef((props, ref) => {
const [focusedState, setFocusedState] = React.useState(false);
const elementRef = React.useRef(null);
const elementRef = React.useRef(ref);
const inputRef = React.useRef(null);
const timer = React.useRef(null);
const lastValue = React.useRef(null);
Expand Down Expand Up @@ -941,6 +941,10 @@ export const InputNumber = React.memo(React.forwardRef((props, ref) => {
ObjectUtils.combinedRefs(inputRef, props.inputRef);
}, [inputRef, props.inputRef]);

React.useEffect(() => {
ObjectUtils.combinedRefs(elementRef, ref);
}, [elementRef, ref]);

useMountEffect(() => {
constructParser();

Expand Down
6 changes: 5 additions & 1 deletion components/lib/inputswitch/InputSwitch.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { classNames, ObjectUtils } from '../utils/Utils';

export const InputSwitch = React.memo(React.forwardRef((props, ref) => {
const [focusedState, setFocusedState] = React.useState(false);
const elementRef = React.useRef(null);
const elementRef = React.useRef(ref);
const inputRef = React.useRef(props.inputRef);
const checked = props.checked === props.trueValue;

Expand Down Expand Up @@ -51,6 +51,10 @@ export const InputSwitch = React.memo(React.forwardRef((props, ref) => {
ObjectUtils.combinedRefs(inputRef, props.inputRef);
}, [inputRef, props.inputRef]);

React.useEffect(() => {
ObjectUtils.combinedRefs(elementRef, ref);
}, [elementRef, ref]);

const hasTooltip = ObjectUtils.isNotEmpty(props.tooltip);
const otherProps = ObjectUtils.findDiffKeys(props, InputSwitch.defaultProps);
const className = classNames('p-inputswitch p-component', {
Expand Down
6 changes: 5 additions & 1 deletion components/lib/knob/Knob.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const minRadians = 4 * Math.PI / 3;
const maxRadians = -Math.PI / 3;

export const Knob = React.memo(React.forwardRef((props, ref) => {
const elementRef = React.useRef(null);
const elementRef = React.useRef(ref);
const enabled = !props.disabled && !props.readOnly;

const [bindWindowMouseMoveListener, unbindWindowMouseMoveListener] = useEventListener({
Expand Down Expand Up @@ -130,6 +130,10 @@ export const Knob = React.memo(React.forwardRef((props, ref) => {
unbindWindowTouchEndListener();
}

React.useEffect(() => {
ObjectUtils.combinedRefs(elementRef, ref);
}, [elementRef, ref]);

const otherProps = ObjectUtils.findDiffKeys(props, Knob.defaultProps);
const className = classNames('p-knob p-component', {
'p-disabled': props.disabled,
Expand Down
6 changes: 5 additions & 1 deletion components/lib/listbox/ListBox.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { ListBoxItem } from './ListBoxItem';

export const ListBox = React.memo(React.forwardRef((props, ref) => {
const [filterValueState, setFilterValueState] = React.useState('');
const elementRef = React.useRef(null);
const elementRef = React.useRef(ref);
const virtualScrollerRef = React.useRef(null);
const optionTouched = React.useRef(false);
const filteredValue = (props.onFilterValueChange ? props.filterValue : filterValueState) || '';
Expand Down Expand Up @@ -254,6 +254,10 @@ export const ListBox = React.memo(React.forwardRef((props, ref) => {
scrollToSelectedIndex();
});

React.useEffect(() => {
ObjectUtils.combinedRefs(elementRef, ref);
}, [elementRef, ref]);

const createHeader = () => {
return props.filter ? <ListBoxHeader filter={filteredValue} onFilter={onFilter} disabled={props.disabled} filterPlaceholder={props.filterPlaceholder} filterInputProps={props.filterInputProps} /> : null;
}
Expand Down
6 changes: 5 additions & 1 deletion components/lib/multiselect/MultiSelect.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export const MultiSelect = React.memo(React.forwardRef((props, ref) => {
const [filterState, setFilterState] = React.useState('');
const [focusedState, setFocusedState] = React.useState(false);
const [overlayVisibleState, setOverlayVisibleState] = React.useState(false);
const elementRef = React.useRef(null);
const elementRef = React.useRef(ref);
const inputRef = React.useRef(props.inputRef);
const labelRef = React.useRef(null);
const overlayRef = React.useRef(null);
Expand Down Expand Up @@ -504,6 +504,10 @@ export const MultiSelect = React.memo(React.forwardRef((props, ref) => {
ObjectUtils.combinedRefs(inputRef, props.inputRef);
}, [inputRef, props.inputRef]);

React.useEffect(() => {
ObjectUtils.combinedRefs(elementRef, ref);
}, [elementRef, ref]);

useUpdateEffect(() => {
if (overlayVisibleState && hasFilter) {
alignOverlay();
Expand Down
6 changes: 5 additions & 1 deletion components/lib/multistatecheckbox/MultiStateCheckbox.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { classNames, ObjectUtils } from '../utils/Utils';

export const MultiStateCheckbox = React.memo(React.forwardRef((props, ref) => {
const [focusedState, setFocusedState] = React.useState(false);
const elementRef = React.useRef(null);
const elementRef = React.useRef(ref);
const equalityKey = props.optionValue ? null : props.dataKey;

const onClick = (event) => {
Expand Down Expand Up @@ -82,6 +82,10 @@ export const MultiStateCheckbox = React.memo(React.forwardRef((props, ref) => {
}
});

React.useEffect(() => {
ObjectUtils.combinedRefs(elementRef, ref);
}, [elementRef, ref]);

const createIcon = () => {
const icon = (selectedOption && selectedOption.icon) || '';
const className = classNames('p-checkbox-icon p-c', {
Expand Down
6 changes: 5 additions & 1 deletion components/lib/orderlist/OrderList.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { OrderListSubList } from './OrderListSubList';

export const OrderList = React.memo(React.forwardRef((props, ref) => {
const [selectionState, setSelectionState] = React.useState([]);
const elementRef = React.useRef(null);
const elementRef = React.useRef(ref);
const reorderDirection = React.useRef(null);

const onItemClick = (event) => {
Expand Down Expand Up @@ -110,6 +110,10 @@ export const OrderList = React.memo(React.forwardRef((props, ref) => {
}
});

React.useEffect(() => {
ObjectUtils.combinedRefs(elementRef, ref);
}, [elementRef, ref]);

const otherProps = ObjectUtils.findDiffKeys(props, OrderList.defaultProps);
const className = classNames('p-orderlist p-component', props.className);

Expand Down
Loading