Skip to content

armgit / macro

Public Imported from GitHub
0

Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.

fix(properties): keep side panel focus when a first value saves (#9266)

gbirman9fa3047a15b6
diff --git a/apps/web/src/features/property/core/Root.test.tsx b/apps/web/src/features/property/core/Root.test.tsx
index de2e68b27b..99f154ca5c 100644
--- a/apps/web/src/features/property/core/Root.test.tsx
+++ b/apps/web/src/features/property/core/Root.test.tsx
@@ -1,6 +1,6 @@
import { fireAndForget } from '@core/util/fireAndForget';
import { cleanup, fireEvent, render, screen } from '@solidjs/testing-library';
-import { createSignal } from 'solid-js';
+import { createSignal, Show } from 'solid-js';
import { afterEach, expect, it, vi } from 'vitest';
import type { EntityProperty, SelectProperty } from '../types';
import { getSelectValues } from '../utils/typeGuards';
@@ -260,6 +260,47 @@ it('returns focus to the pill after the editor took it', async () => {
expect(document.activeElement).toBe(pill);
});
+it('returns focus to its own root when another shows the same property', async () => {
+ const [replaced, setReplaced] = createSignal(false);
+ const Pill = () => {
+ const ctx = useProperty();
+ return (
+ <Show
+ when={replaced()}
+ fallback={
+ <button onClick={(event) => ctx.openEditor(event.currentTarget)}>
+ Set
+ </button>
+ }
+ >
+ <button>Saved</button>
+ </Show>
+ );
+ };
+ const Close = () => {
+ const ctx = useProperty();
+ return <button onClick={() => ctx.closeEditor()}>Close</button>;
+ };
+ render(() => (
+ <>
+ <Root property={priority}>
+ <button>Title row pill</button>
+ </Root>
+ <Root property={priority}>
+ <Pill />
+ <Close />
+ </Root>
+ </>
+ ));
+
+ fireEvent.click(screen.getByText('Set'));
+ setReplaced(true);
+ fireEvent.click(screen.getByText('Close'));
+ await nextTask();
+
+ expect(document.activeElement).toBe(screen.getByText('Saved'));
+});
+
it('leaves focus in the field the editor found it in', async () => {
const { title, pill } = renderEditor();
diff --git a/apps/web/src/features/property/core/Root.tsx b/apps/web/src/features/property/core/Root.tsx
index 618497b9f2..daaca6e94e 100644
--- a/apps/web/src/features/property/core/Root.tsx
+++ b/apps/web/src/features/property/core/Root.tsx
@@ -113,6 +113,7 @@ export function Root(props: PropertyRootProps) {
// A touch editor leaves focus in the field the user was typing in (a
// composer's title), and a picker sheet hands it back there.
let focusAtOpen: Element | null = null;
+ let rootElement: HTMLDivElement | undefined;
// Focus restoration helper - used by both closeEditor and onOpenChange
// When a value is saved, the component may remount (due to reactive updates),
@@ -138,8 +139,11 @@ export function Root(props: PropertyRootProps) {
return;
}
- // Fallback: find the trigger by property ID (handles remount case)
- const root = document.querySelector(`[data-property-id="${propertyId}"]`);
+ // Fallback: find the trigger by property ID (handles remount case). The
+ // title row and side panel show the same ID, so prefer this root's own.
+ const root = rootElement?.isConnected
+ ? rootElement
+ : document.querySelector(`[data-property-id="${propertyId}"]`);
// Row actions can precede the value editor; restore focus to its trigger.
const trigger = root?.querySelector<HTMLButtonElement>(
'button:not([data-property-row-action])'
@@ -202,6 +206,7 @@ export function Root(props: PropertyRootProps) {
fitViewport
>
<div
+ ref={rootElement}
class={cn('property-root', local.class)}
data-property
data-property-id={local.property.propertyId}
diff --git a/apps/web/src/features/property/side-panel/properties/EntityPropertiesSection.test.tsx b/apps/web/src/features/property/side-panel/properties/EntityPropertiesSection.test.tsx
index d888752cb4..7999a4cb5f 100644
--- a/apps/web/src/features/property/side-panel/properties/EntityPropertiesSection.test.tsx
+++ b/apps/web/src/features/property/side-panel/properties/EntityPropertiesSection.test.tsx
@@ -36,7 +36,7 @@ vi.mock('@core/util/useSplitNavigationHandler', () => ({
vi.mock('@property', () => ({
Property: {
Root: (props: { property: Property }) => (
- <span>{JSON.stringify(props.property.value)}</span>
+ <button>{JSON.stringify(props.property.value)}</button>
),
},
useProperty: vi.fn(),
@@ -434,6 +434,29 @@ it('shows implicit task defaults as pinned while preserving deletion guards and
expect(mocks.remove).not.toHaveBeenCalled();
});
+it('keeps a focused value mounted while its placeholder gets an assignment', () => {
+ const placeholder = { ...field('Project'), propertyId: 'pending:Project' };
+ const [properties, setProperties] = createSignal<Property[]>([]);
+ mocks.getProperties = properties;
+ render(() => (
+ <EntityPropertiesSection
+ entityId="task"
+ entityType="TASK"
+ canEdit
+ showTags={false}
+ defaultProperties={() => [placeholder]}
+ />
+ ));
+ const value = screen.getByRole('button', { name: 'null' });
+ value.focus();
+
+ setProperties([{ ...field('Project', 'Launch'), propertyId: 'optimistic' }]);
+ setProperties([{ ...field('Project', 'Launch'), propertyId: 'assigned' }]);
+
+ expect(document.activeElement).toBe(value);
+ expect(value.textContent).toBe('"Launch"');
+});
+
it('pins and unpins a virtual default without creating or deleting an assignment', async () => {
const placeholder = { ...field('Project'), propertyId: 'pending:Project' };
const [pins, setPins] = createSignal<string[] | undefined>();
diff --git a/apps/web/src/features/property/side-panel/properties/EntityPropertiesSection.tsx b/apps/web/src/features/property/side-panel/properties/EntityPropertiesSection.tsx
index cf825df2f6..5e90f20f81 100644
--- a/apps/web/src/features/property/side-panel/properties/EntityPropertiesSection.tsx
+++ b/apps/web/src/features/property/side-panel/properties/EntityPropertiesSection.tsx
@@ -29,6 +29,7 @@ import { getEntityValues, hasValue } from '@property/utils';
import { useBulkSaveEntityPropertiesMutation } from '@queries/properties/entity';
import { useTagsQuery } from '@queries/properties/tags';
import type { EntityType } from '@service-properties/generated/schemas/entityType';
+import { Key } from '@solid-primitives/keyed';
import { Badge, Button, Layer } from '@ui';
import { cn } from '@ui/utils/classname';
import {
@@ -328,37 +329,37 @@ export function EntityPropertiesSection(props: EntityPropertiesSectionProps) {
'mb-3'
)}
>
- <For each={gridProperties()}>
+ <Key each={gridProperties()} by="propertyDefinitionId">
{(property) => (
<SidePanelPropertyRow
entityId={props.entityId}
getEmptyLabel={props.getEmptyLabel}
- property={property}
+ property={property()}
canRemoveFromEntity={
!defaultPinnedDefinitionIds().has(
- property.propertyDefinitionId
+ property().propertyDefinitionId
) &&
!(
- isPendingProperty(property) &&
+ isPendingProperty(property()) &&
props
.defaultProperties?.()
.some(
(placeholder) =>
placeholder.propertyDefinitionId ===
- property.propertyDefinitionId
+ property().propertyDefinitionId
)
)
}
canPinPendingProperty={props
.defaultTitlePropertyDefinitionIds?.()
- .includes(property.propertyDefinitionId)}
+ .includes(property().propertyDefinitionId)}
onRemovePendingProperty={removePendingProperty}
onPropertyPinned={
props.onPropertyPinned ? pinProperty : undefined
}
/>
)}
- </For>
+ </Key>
</SidePanel.Grid>
</Show>