fix: flashElement scrolls canvas too much. (#7547)

This commit is contained in:
Ashok Kumar M 2021-09-16 22:24:12 +05:30 committed by GitHub
parent 1d101300a5
commit 34c4dad0ac
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 28 additions and 17 deletions

View File

@ -45,10 +45,12 @@ export const useNavigateToWidget = () => {
selectWidget(widgetId, false);
navigateToCanvas(params, window.location.pathname, pageId, widgetId);
flashElementsById(widgetId);
// Navigating to a widget from query pane seems to make the property pane
// appear below the entity explorer hence adding a timeout here
setTimeout(() => {
if (params.pageId === pageId) {
flashElementsById(widgetId);
}
dispatch(forceOpenPropertyPane(widgetId));
}, 0);
};

View File

@ -173,8 +173,8 @@ export const flashElementsById = (id: string | string[], timeout = 0) => {
el?.scrollIntoView({
behavior: "smooth",
block: "nearest",
inline: "nearest",
block: "center",
inline: "center",
});
if (el) flashElement(el);

View File

@ -10,6 +10,7 @@ import WidgetStyleContainer, {
} from "components/designSystems/appsmith/WidgetStyleContainer";
import { pick } from "lodash";
import { ComponentProps } from "widgets/BaseComponent";
import { MAIN_CONTAINER_WIDGET_ID } from "constants/WidgetConstants";
const scrollContents = css`
overflow-y: auto;
@ -50,10 +51,9 @@ const StyledContainerComponent = styled.div<
}
}`;
function ContainerComponent(props: ContainerComponentProps) {
function ContainerComponentWrapper(props: ContainerComponentProps) {
const containerStyle = props.containerStyle || "card";
const containerRef: RefObject<HTMLDivElement> = useRef<HTMLDivElement>(null);
useCanvasMinHeightUpdateHook(props.widgetId, props.minHeight);
useEffect(() => {
if (!props.shouldScrollContents) {
const supportsNativeSmoothScroll =
@ -68,6 +68,26 @@ function ContainerComponent(props: ContainerComponentProps) {
}
}, [props.shouldScrollContents]);
return (
<StyledContainerComponent
{...props}
className={`${
props.shouldScrollContents ? getCanvasClassName() : ""
} ${generateClassName(props.widgetId)}`}
containerStyle={containerStyle}
// Before you remove: generateClassName is used for bounding the resizables within this canvas
// getCanvasClassName is used to add a scrollable parent.
ref={containerRef}
>
{props.children}
</StyledContainerComponent>
);
}
function ContainerComponent(props: ContainerComponentProps) {
useCanvasMinHeightUpdateHook(props.widgetId, props.minHeight);
return props.widgetId === MAIN_CONTAINER_WIDGET_ID ? (
<ContainerComponentWrapper {...props} />
) : (
<WidgetStyleContainer
{...pick(props, [
"widgetId",
@ -79,18 +99,7 @@ function ContainerComponent(props: ContainerComponentProps) {
"boxShadowColor",
])}
>
<StyledContainerComponent
{...props}
className={`${
props.shouldScrollContents ? getCanvasClassName() : ""
} ${generateClassName(props.widgetId)}`}
containerStyle={containerStyle}
// Before you remove: generateClassName is used for bounding the resizables within this canvas
// getCanvasClassName is used to add a scrollable parent.
ref={containerRef}
>
{props.children}
</StyledContainerComponent>
<ContainerComponentWrapper {...props} />
</WidgetStyleContainer>
);
}