feat: migrate button groups and toggle buttons with focus regressions
This commit is contained in:
@@ -1,10 +1,11 @@
|
||||
<script setup lang="ts">
|
||||
import { useInheritedDisabled } from "../field/disabled";
|
||||
import { computed, ref, watch } from "vue";
|
||||
import { computed, inject, ref, watch } from "vue";
|
||||
import { Primitive } from "reka-ui";
|
||||
import type { ButtonHTMLAttributes } from "vue";
|
||||
import { buttonVariants, type ButtonVariants } from "@heroui-vue/styles";
|
||||
import Spinner from "../spinner/Spinner.vue";
|
||||
import { buttonGroupContextKey } from "../button-group/context";
|
||||
defineOptions({ inheritAttrs: false });
|
||||
const props = withDefaults(
|
||||
defineProps<{
|
||||
@@ -18,11 +19,56 @@ const props = withDefaults(
|
||||
disabled?: boolean;
|
||||
loading?: boolean;
|
||||
type?: ButtonHTMLAttributes["type"];
|
||||
/** Marks a direct ButtonGroup child (see BUTTON_GROUP_CHILD). */
|
||||
__button_group_child?: boolean;
|
||||
}>(),
|
||||
{ type: "button" },
|
||||
{
|
||||
type: "button",
|
||||
variant: undefined,
|
||||
size: undefined,
|
||||
fullWidth: undefined,
|
||||
isDisabled: undefined,
|
||||
disabled: undefined,
|
||||
},
|
||||
);
|
||||
const buttonGroupContext = inject(buttonGroupContextKey, undefined);
|
||||
const isButtonGroupChild = computed(() => props.__button_group_child === true);
|
||||
const finalSize = computed(
|
||||
() =>
|
||||
props.size ??
|
||||
(isButtonGroupChild.value ? buttonGroupContext?.value.size : undefined),
|
||||
);
|
||||
const finalVariant = computed(
|
||||
() =>
|
||||
props.variant ??
|
||||
(isButtonGroupChild.value ? buttonGroupContext?.value.variant : undefined),
|
||||
);
|
||||
const finalFullWidth = computed(
|
||||
() =>
|
||||
props.fullWidth ??
|
||||
(isButtonGroupChild.value
|
||||
? buttonGroupContext?.value.fullWidth
|
||||
: undefined),
|
||||
);
|
||||
const groupDisabled = computed(() =>
|
||||
isButtonGroupChild.value
|
||||
? Boolean(buttonGroupContext?.value.isDisabled)
|
||||
: false,
|
||||
);
|
||||
/**
|
||||
* Upstream nullish precedence: explicit child props override ButtonGroup defaults.
|
||||
* Fieldset/native constraints still force disabled through useInheritedDisabled.
|
||||
*/
|
||||
const explicitDisabled = computed(
|
||||
() => props.isDisabled ?? props.disabled ?? undefined,
|
||||
);
|
||||
const localDisabled = computed(() =>
|
||||
explicitDisabled.value === undefined
|
||||
? groupDisabled.value
|
||||
: Boolean(explicitDisabled.value),
|
||||
);
|
||||
const pending = computed(() => props.isPending || props.loading);
|
||||
const disabled = useInheritedDisabled(() => props.isDisabled || props.disabled);
|
||||
const disabled = useInheritedDisabled(() => localDisabled.value);
|
||||
const hovered = ref(false),
|
||||
pressed = ref(false),
|
||||
focused = ref(false),
|
||||
@@ -55,7 +101,14 @@ function focus(e: FocusEvent) {
|
||||
:as-child="asChild"
|
||||
v-bind="$attrs"
|
||||
:type="type"
|
||||
:class="buttonVariants({ variant, size, fullWidth, isIconOnly })"
|
||||
:class="
|
||||
buttonVariants({
|
||||
variant: finalVariant,
|
||||
size: finalSize,
|
||||
fullWidth: finalFullWidth,
|
||||
isIconOnly,
|
||||
})
|
||||
"
|
||||
:disabled="disabled"
|
||||
:aria-disabled="pending || disabled || undefined"
|
||||
:aria-busy="pending || undefined"
|
||||
|
||||
Reference in New Issue
Block a user