Skip to content

Commit

Permalink
Merge pull request #295 from contentstack/VE-3974-focus-loses-when-a-…
Browse files Browse the repository at this point in the history
…field-is-deleted
  • Loading branch information
sairajchouhan authored Nov 11, 2024
2 parents 1eb5894 + 7a9a14e commit ebc671b
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 5 deletions.
9 changes: 9 additions & 0 deletions src/visualBuilder/components/FieldToolbar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ const TOOLTIP_TOP_EDGE_BUFFER = 96;

interface MultipleFieldToolbarProps {
eventDetails: VisualBuilderCslpEventDetails;
hideOverlay: () => void;
};

function handleReplaceAsset(fieldMetadata: CslpData) {
Expand Down Expand Up @@ -309,6 +310,14 @@ function FieldToolbarComponent(
fetchFieldSchema();
}, [fieldMetadata]);

useEffect(() => {
visualBuilderPostMessage?.on(VisualBuilderPostMessageEvents.DELETE_INSTANCE, (args: { data: { path: string } }) => {
if(args.data?.path === fieldMetadata.instance.fieldPathWithIndex){
props.hideOverlay()
}
})
}, [])

const multipleFieldToolbarButtonClasses = classNames(
"visual-builder__button visual-builder__button--secondary",
visualBuilderStyles()["visual-builder__button"],
Expand Down
9 changes: 6 additions & 3 deletions src/visualBuilder/generators/generateToolbar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,17 @@ import FieldLabelWrapperComponent from "../components/fieldLabelWrapper";

export function appendFocusedToolbar(
eventDetails: VisualBuilderCslpEventDetails,
focusedToolbarElement: HTMLDivElement
focusedToolbarElement: HTMLDivElement,
hideOverlay: () => void
): void {
appendFieldPathDropdown(eventDetails, focusedToolbarElement);
appendFieldToolbar(eventDetails, focusedToolbarElement);
appendFieldToolbar(eventDetails, focusedToolbarElement, hideOverlay);
}

export function appendFieldToolbar(
eventDetails: VisualBuilderCslpEventDetails,
focusedToolbarElement: HTMLDivElement
focusedToolbarElement: HTMLDivElement,
hideOverlay: () => void
): void {
if (
focusedToolbarElement.querySelector(
Expand All @@ -35,6 +37,7 @@ export function appendFieldToolbar(
render(
<FieldToolbarComponent
eventDetails={eventDetails}
hideOverlay={hideOverlay}
/>,
wrapper
);
Expand Down
12 changes: 10 additions & 2 deletions src/visualBuilder/listeners/mouseClick.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ type AddFocusOverlayParams = Pick<
type AddFocusedToolbarParams = Pick<
EventListenerHandlerParams,
"eventDetails" | "focusedToolbar"
>;
> & { hideOverlay: () => void };

function addOverlay(params: AddFocusOverlayParams) {
if (!params.overlayWrapper || !params.editableElement) return;
Expand All @@ -53,7 +53,7 @@ export function addFocusedToolbar(params: AddFocusedToolbarParams): void {

if (!editableElement || !params.focusedToolbar) return;

appendFocusedToolbar(params.eventDetails, params.focusedToolbar);
appendFocusedToolbar(params.eventDetails, params.focusedToolbar, params.hideOverlay);
}

async function handleBuilderInteraction(
Expand Down Expand Up @@ -143,6 +143,14 @@ async function handleBuilderInteraction(
addFocusedToolbar({
eventDetails: eventDetails,
focusedToolbar: params.focusedToolbar,
hideOverlay: () => {
hideOverlay({
visualBuilderContainer: params.visualBuilderContainer,
visualBuilderOverlayWrapper: params.overlayWrapper,
focusedToolbar: params.focusedToolbar,
resizeObserver: params.resizeObserver,
});
}
});

const { content_type_uid, fieldPath, cslpValue } = fieldMetadata;
Expand Down

0 comments on commit ebc671b

Please sign in to comment.