From 4c639da39edab16cdb198db38d6d158197ebf999 Mon Sep 17 00:00:00 2001 From: Robert Niznik Date: Tue, 22 Oct 2024 09:10:58 -0400 Subject: [PATCH] fix(components): fix `Button` detection of `Select` context (#1450) --- .changeset/moody-ways-rule.md | 5 +++++ packages/components/src/Button.tsx | 8 +++++--- 2 files changed, 10 insertions(+), 3 deletions(-) create mode 100644 .changeset/moody-ways-rule.md diff --git a/.changeset/moody-ways-rule.md b/.changeset/moody-ways-rule.md new file mode 100644 index 000000000..5e4896caf --- /dev/null +++ b/.changeset/moody-ways-rule.md @@ -0,0 +1,5 @@ +--- +"@launchpad-ui/components": patch +--- + +Fix `Button` detection of `Select` context diff --git a/packages/components/src/Button.tsx b/packages/components/src/Button.tsx index de69800bf..d5320c3a9 100644 --- a/packages/components/src/Button.tsx +++ b/packages/components/src/Button.tsx @@ -3,11 +3,12 @@ import type { ForwardedRef } from 'react'; import type { ButtonProps as AriaButtonProps } from 'react-aria-components'; import { cva, cx } from 'class-variance-authority'; -import { forwardRef } from 'react'; +import { forwardRef, useContext } from 'react'; import { Button as AriaButton, Provider, SelectContext, + SelectStateContext, TextContext, composeRenderProps, useSlottedContext, @@ -45,13 +46,14 @@ const _Button = ( ref: ForwardedRef, ) => { const selectContext = useSlottedContext(SelectContext); + const state = useContext(SelectStateContext); return ( - selectContext - ? cx(input(), styles.select, selectContext.isInvalid && styles.invalid, className) + state + ? cx(input(), styles.select, selectContext?.isInvalid && styles.invalid, className) : button({ ...renderProps, size, variant, className }), )} >