Skip to content

Commit

Permalink
fix(rac): update plasmic variant for combobox in classname callback
Browse files Browse the repository at this point in the history
Change-Id: I115ba2f46b84ed9d83854f7e4fbbffabe56937e9
GitOrigin-RevId: 43f11f776b6185b93f8f1b4b0e0f81498166a064
  • Loading branch information
sarahsga authored and actions-user committed Nov 21, 2024
1 parent 4d661c9 commit c17d130
Showing 1 changed file with 13 additions and 15 deletions.
28 changes: 13 additions & 15 deletions plasmicpkgs/react-aria/src/registerComboBox.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import React, { useEffect, useMemo } from "react";
import React, { useCallback, useEffect, useMemo } from "react";
import {
ComboBox,
ComboBoxProps,
ComboBoxRenderProps,
ComboBoxStateContext,
} from "react-aria-components";
import { getCommonProps } from "./common";
Expand Down Expand Up @@ -70,11 +71,20 @@ export function BaseComboBox(props: BaseComboboxProps) {
setControlContextData,
plasmicUpdateVariant,
className,
isDisabled,
isOpen: _isOpen, // uncontrolled if not selected in canvas/edit mode
...rest
} = props;

const classNameProp = useCallback(
({ isDisabled }: ComboBoxRenderProps) => {
plasmicUpdateVariant?.({
disabled: isDisabled,
});
return className ?? "";
},
[className, plasmicUpdateVariant]
);

const idManager = useMemo(() => new ListBoxItemIdManager(), []);

useEffect(() => {
Expand All @@ -85,20 +95,8 @@ export function BaseComboBox(props: BaseComboboxProps) {
});
}, []);

// NOTE: Aria <Combobox> does not support render props, neither does it provide an onDisabledChange event, so we have to manually update the disabled state.
useEffect(() => {
plasmicUpdateVariant?.({
disabled: isDisabled,
});
}, [isDisabled, plasmicUpdateVariant]);

return (
<ComboBox
isDisabled={isDisabled}
// Not calling plasmicUpdateVariant within className callback (which has access to render props) because it would then run on every render
className={className}
{...rest}
>
<ComboBox className={classNameProp} {...rest}>
<PlasmicPopoverTriggerContext.Provider value={true}>
<PlasmicListBoxContext.Provider
value={{
Expand Down

0 comments on commit c17d130

Please sign in to comment.