Skip to content

Commit

Permalink
Fix #5561: Inplace respect active prop
Browse files Browse the repository at this point in the history
  • Loading branch information
melloware committed Dec 8, 2023
1 parent 6b14037 commit b1887c7
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion components/lib/inplace/Inplace.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import * as React from 'react';
import { localeOption, PrimeReactContext } from '../api/Api';
import { Button } from '../button/Button';
import { useHandleStyle } from '../componentbase/ComponentBase';
import { useUpdateEffect } from '../hooks/Hooks';
import { TimesIcon } from '../icons/times';
import { classNames, IconUtils, mergeProps, ObjectUtils } from '../utils/Utils';
import { InplaceBase } from './InplaceBase';
Expand All @@ -13,7 +14,7 @@ export const Inplace = React.forwardRef((inProps, ref) => {
const context = React.useContext(PrimeReactContext);
const props = InplaceBase.getProps(inProps, context);

const [activeState, setActiveState] = React.useState(props.active);
const [activeState, setActiveState] = React.useState(undefined);
const elementRef = React.useRef(null);
const active = props.onToggle ? props.active : activeState;
const metaData = {
Expand Down Expand Up @@ -44,6 +45,10 @@ export const Inplace = React.forwardRef((inProps, ref) => {
};

const close = (event) => {
if (props.disabled) {
return;
}

props.onClose && props.onClose(event);

if (props.onToggle) {
Expand Down Expand Up @@ -133,6 +138,10 @@ export const Inplace = React.forwardRef((inProps, ref) => {
});
};

useUpdateEffect(() => {
props.active ? open(null) : close(null);
}, [props.active]);

React.useImperativeHandle(ref, () => ({
props,
getElement: () => elementRef.current
Expand Down

0 comments on commit b1887c7

Please sign in to comment.