diff --git a/resources/js/components/forms/logic/LogicTree.vue b/resources/js/components/forms/logic/LogicTree.vue index a380bd48dc5..e9d3f5e96a8 100644 --- a/resources/js/components/forms/logic/LogicTree.vue +++ b/resources/js/components/forms/logic/LogicTree.vue @@ -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(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(`[data-page-actions="${id}"]`)?.focus()); - } - + focusSelection(selection); return; } @@ -251,8 +267,9 @@ 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" /> - + @@ -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, @@ -355,6 +373,6 @@ onUnmounted(() => {
diff --git a/resources/js/components/forms/logic/LogicTreeField.vue b/resources/js/components/forms/logic/LogicTreeField.vue index 2d5ec671cfd..de92d9b81a3 100644 --- a/resources/js/components/forms/logic/LogicTreeField.vue +++ b/resources/js/components/forms/logic/LogicTreeField.vue @@ -31,10 +31,11 @@ const iconClass = computed(() => { :class="['size-4 shrink-0', iconClass]" aria-hidden="true" /> - + +