fix: retain pending Toast and Table fidelity corrections
This commit is contained in:
@@ -13,7 +13,16 @@ import {
|
||||
onUpdated,
|
||||
type PropType,
|
||||
} from "vue";
|
||||
import { tableContextKey, tableRowContextKey, type TableKey } from "./context";
|
||||
import {
|
||||
tableBodyContextKey,
|
||||
tableContextKey,
|
||||
tableRowContextKey,
|
||||
type TableKey,
|
||||
} from "./context";
|
||||
|
||||
/** Nested controls own their own activation; row click must not also toggle selection. */
|
||||
const INTERACTIVE_SELECTOR =
|
||||
"button, a, input, select, textarea, label, [role='button'], [role='link'], [contenteditable='true'], [data-choice-input], [data-slot='checkbox-content'], [data-slot='checkbox-control'], [data-slot='checkbox-indicator'], [data-slot='radio-content'], [data-slot='radio-control'], [data-slot='radio-indicator']";
|
||||
|
||||
export default defineComponent({
|
||||
name: "TableRow",
|
||||
@@ -28,17 +37,26 @@ export default defineComponent({
|
||||
setup(props, { slots }) {
|
||||
const attrs = useAttrs();
|
||||
const ctx = inject(tableContextKey, null);
|
||||
const bodyCtx = inject(tableBodyContextKey, null);
|
||||
const element = ref<HTMLElement | null>(null);
|
||||
let unregisterBodyRow: (() => void) | undefined;
|
||||
watch(
|
||||
[() => props.rowKey, element],
|
||||
([key, node], previous) => {
|
||||
if (previous) ctx?.navigation?.register(previous[0], null);
|
||||
if (!node?.closest("thead"))
|
||||
if (previous?.[0] != null) ctx?.navigation?.register(previous[0], null);
|
||||
if (!node?.closest("thead")) {
|
||||
ctx?.navigation?.register(key, node, () => props.isDisabled);
|
||||
if (!unregisterBodyRow && bodyCtx && node)
|
||||
unregisterBodyRow = bodyCtx.registerRow();
|
||||
}
|
||||
},
|
||||
{ flush: "sync" },
|
||||
{ flush: "sync", immediate: true },
|
||||
);
|
||||
onBeforeUnmount(() => ctx?.navigation?.register(props.rowKey, null));
|
||||
onBeforeUnmount(() => {
|
||||
ctx?.navigation?.register(props.rowKey, null);
|
||||
unregisterBodyRow?.();
|
||||
unregisterBodyRow = undefined;
|
||||
});
|
||||
onUpdated(() => ctx?.navigation?.refresh());
|
||||
const isSelected = computed(
|
||||
() => ctx?.isRowSelected(props.rowKey) ?? false,
|
||||
@@ -61,6 +79,9 @@ export default defineComponent({
|
||||
get hasChildItems() {
|
||||
return props.hasChildItems;
|
||||
},
|
||||
get level() {
|
||||
return props.level;
|
||||
},
|
||||
});
|
||||
return () => {
|
||||
// Vue DOM merge: user onClick is first in the array, so
|
||||
@@ -75,8 +96,17 @@ export default defineComponent({
|
||||
"data-selected": isSelected.value || undefined,
|
||||
"data-disabled": isDisabled.value || undefined,
|
||||
"data-expanded": isExpanded.value || undefined,
|
||||
"data-level": props.level,
|
||||
"aria-expanded": props.hasChildItems ? isExpanded.value : undefined,
|
||||
"aria-level": props.level,
|
||||
// 1-based level for CSS indent (matches upstream --table-row-level).
|
||||
style:
|
||||
props.level != null
|
||||
? ({ "--table-row-level": String(props.level) } as Record<
|
||||
string,
|
||||
string
|
||||
>)
|
||||
: undefined,
|
||||
"aria-selected":
|
||||
ctx && ctx.selectionMode.value !== "none"
|
||||
? isSelected.value
|
||||
@@ -95,11 +125,7 @@ export default defineComponent({
|
||||
if (event.defaultPrevented) return;
|
||||
if (isDisabled.value) return;
|
||||
const target = event.target as HTMLElement | null;
|
||||
if (
|
||||
target?.closest(
|
||||
"button, a, input, select, textarea, [role='button'], [role='link']",
|
||||
)
|
||||
) {
|
||||
if (target?.closest(INTERACTIVE_SELECTOR)) {
|
||||
return;
|
||||
}
|
||||
ctx?.toggleSelect(props.rowKey, event);
|
||||
@@ -108,11 +134,7 @@ export default defineComponent({
|
||||
if (event.defaultPrevented || isDisabled.value) return;
|
||||
if (event.key !== " " && event.key !== "Spacebar") return;
|
||||
const target = event.target as HTMLElement | null;
|
||||
if (
|
||||
target?.closest(
|
||||
"input, select, textarea, button, a, [role='button'], [role='link'], [contenteditable='true']",
|
||||
)
|
||||
) {
|
||||
if (target?.closest(INTERACTIVE_SELECTOR)) {
|
||||
return;
|
||||
}
|
||||
event.preventDefault();
|
||||
|
||||
Reference in New Issue
Block a user