Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 30 additions & 12 deletions resources/js/components/forms/logic/LogicTree.vue
Original file line number Diff line number Diff line change
Expand Up @@ -186,23 +186,39 @@ watch(() => props.selected, (selection) => {
// Fields moving or density changing can shift rows without always resizing the tree.
watch(() => [props.pages, props.density], () => nextTick(measureAdjacentRightCells), { deep: true });

// Puts focus back on the tree item a selection came from, once its inspector closes.
const focusSelection = (selection: Selection | null) => {
if (!selection) return;

const selector = {
[SelectionType.Field]: `[data-field-id="${selection.id}"] button`,
[SelectionType.Page]: `[data-form-page="${selection.id}"] .linked-list__page-name button`,
[SelectionType.Action]: `[data-page-actions="${selection.id}"]`,
}[selection.type];

nextTick(() => tree.value?.querySelector<HTMLElement>(selector)?.focus());
};

const closeMobileInspector = () => {
isInspectorOpen.value = false;
focusSelection(props.selected);
};

const onEscape = (event: KeyboardEvent) => {
if (event.key !== 'Escape') return;

// Leave this Esc to an open dropdown, popover or modal, so it only closes that.
if (event.defaultPrevented || document.querySelector('[data-dismissable-layer]')) return;

if (isInspectorOpen.value) {
isInspectorOpen.value = false;
closeMobileInspector();
return;
}

if (props.selected) {
const { type, id } = props.selected;
const selection = props.selected;
emit('select', null);

// Closing the page buttons' inspector puts focus back on the button that opened it.
if (type === SelectionType.Action) {
nextTick(() => tree.value?.querySelector<HTMLElement>(`[data-page-actions="${id}"]`)?.focus());
}

focusSelection(selection);
return;
}

Expand Down Expand Up @@ -251,16 +267,17 @@ onUnmounted(() => {
class="logic-arrow size-3! shrink-0 -ms-2.5 relative -top-0.25 text-blue-400 dark:text-blue-500"
aria-hidden="true"
/>
<div
class="mx-auto flex w-full shrink-0 justify-center items-center gap-2 rounded-xl border border-dashed border-gray-300 px-3.5 py-2 text-xs font-medium text-gray-850 bg-white dark:border-gray-700 dark:bg-gray-900 dark:text-gray-200"
<button
type="button"
class="mx-auto flex w-full shrink-0 cursor-pointer justify-center items-center gap-2 rounded-xl border border-dashed border-gray-300 px-3.5 py-2 text-xs font-medium text-gray-850 bg-white dark:border-gray-700 dark:bg-gray-900 dark:text-gray-200"
:class="{
'w-[85%]!': isConnectorDestination(pageIndex),
'ring-1 ring-blue-500 border-transparent': isPageSelected(page),
}"
>
<Icon name="page" class="size-4 shrink-0 -ms-1.5 text-gray-500 dark:text-gray-400" aria-hidden="true" />
<span class="truncate">{{ pageTitle(page, pageIndex) }}</span>
</div>
</button>
</div>
</div>

Expand All @@ -286,6 +303,7 @@ onUnmounted(() => {
class="cursor-pointer"
:class="{
'linked-list__fieldset': field.type === 'import',
'show-focus-within': field.type !== 'import',
'linked-list__hidden-field': field.config?.hidden,
'linked-list__connector': fieldConnection(field),
'linked-list__page-leap': fieldConnection(field)?.leap,
Expand Down Expand Up @@ -355,6 +373,6 @@ onUnmounted(() => {
<div
class="mobile-panel-backdrop"
:data-visible="isInspectorOpen"
@click="isInspectorOpen = false"
@click="closeMobileInspector"
/>
</template>
5 changes: 3 additions & 2 deletions resources/js/components/forms/logic/LogicTreeField.vue
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,11 @@ const iconClass = computed(() => {
:class="['size-4 shrink-0', iconClass]"
aria-hidden="true"
/>
<span class="linked-list__field-name min-w-0 flex-1">
<!-- A real button so the cell can be reached with Tab. Its click bubbles up to the cell, which does the selecting. -->
<button type="button" class="linked-list__field-name show-focus-within_target min-w-0 flex-1 cursor-pointer self-start text-start focus:outline-none">
<FieldNumber :field-key="field.handle" />
{{ __(field.config?.display) || field.handle }}
</span>
</button>
<span
v-if="field.config?.hidden"
class="inline-flex size-4 shrink-0"
Expand Down
Loading