Skip to content

Commit

Permalink
Merge pull request #6325 from melloware/forwardref
Browse files Browse the repository at this point in the history
FloatLabel/StepperPanel proper use of forwardRef
  • Loading branch information
gucal authored Apr 8, 2024
2 parents 860dff3 + f932f41 commit 27c32d6
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
10 changes: 8 additions & 2 deletions components/lib/floatlabel/FloatLabel.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,28 @@ import * as React from 'react';
import { PrimeReactContext } from '../api/Api';
import { useHandleStyle } from '../componentbase/ComponentBase';
import { useMergeProps } from '../hooks/Hooks';
import { classNames } from '../utils/Utils';
import { classNames, ObjectUtils } from '../utils/Utils';
import { FloatLabelBase } from './FloatLabelBase';

export const FloatLabel = React.memo(
React.forwardRef((inProps) => {
React.forwardRef((inProps, ref) => {
const mergeProps = useMergeProps();
const context = React.useContext(PrimeReactContext);
const props = FloatLabelBase.getProps(inProps, context);
const elementRef = React.useRef(ref);
const { ptm, cx, isUnstyled } = FloatLabelBase.setMetaData({
props
});

useHandleStyle(FloatLabelBase.css.styles, isUnstyled, { name: 'floatlabel' });

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

const rootProps = mergeProps(
{
ref: elementRef,
className: classNames(cx('root'))
},
FloatLabelBase.getOtherProps(props),
Expand Down
10 changes: 8 additions & 2 deletions components/lib/stepperpanel/StepperPanel.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,25 @@
import * as React from 'react';
import { PrimeReactContext } from '../api/Api';
import { useHandleStyle } from '../componentbase/ComponentBase';
import { ObjectUtils } from '../utils/Utils';
import { StepperPanelBase } from './StepperPanelBase';

export const StepperPanel = React.memo(
React.forwardRef((inProps) => {
React.forwardRef((inProps, ref) => {
const context = React.useContext(PrimeReactContext);
const props = StepperPanelBase.getProps(inProps, context);
const elementRef = React.useRef(ref);
const { isUnstyled } = StepperPanelBase.setMetaData({
props
});

useHandleStyle(StepperPanelBase.css.styles, isUnstyled, { name: 'StepperPanel' });

return <>{props.children}</>;
React.useEffect(() => {
ObjectUtils.combinedRefs(elementRef, ref);
}, [elementRef, ref]);

return <span ref={ref}>{props.children}</span>;
})
);

Expand Down

0 comments on commit 27c32d6

Please sign in to comment.