@@ -14,7 +14,11 @@ import {
1414 useState ,
1515} from 'react' ;
1616import { FocusScope , Key , useKeyboard } from 'react-aria' ;
17- import { Section as BaseSection , Item , ListState } from 'react-stately' ;
17+ import {
18+ Section as BaseSection ,
19+ ListState ,
20+ Item as ReactAriaItem ,
21+ } from 'react-stately' ;
1822
1923import { useEvent } from '../../../_internal' ;
2024import { useWarn } from '../../../_internal/hooks/use-warn' ;
@@ -119,6 +123,8 @@ export interface CubeFilterPickerProps<T>
119123 mods ?: Record < string , boolean > ;
120124 /** Whether the filter picker is clearable using a clear button in the rightIcon slot */
121125 isClearable ?: boolean ;
126+ /** Callback called when the clear button is pressed */
127+ onClear ?: ( ) => void ;
122128}
123129
124130const PROP_STYLES = [ ...BASE_STYLES , ...OUTER_STYLES , ...COLOR_STYLES ] ;
@@ -441,7 +447,7 @@ export const FilterPicker = forwardRef(function FilterPicker<T extends object>(
441447 if ( ! child || typeof child !== 'object' ) return ;
442448 const element = child as ReactElement ;
443449
444- if ( element . type === Item ) {
450+ if ( element . type === ReactAriaItem ) {
445451 const props = element . props as any ;
446452 const label =
447453 props . textValue ||
@@ -523,7 +529,7 @@ export const FilterPicker = forwardRef(function FilterPicker<T extends object>(
523529 if ( ! child || typeof child !== 'object' ) return ;
524530 const element = child as ReactElement ;
525531
526- if ( element . type === Item ) {
532+ if ( element . type === ReactAriaItem ) {
527533 const childKey = String ( element . key ) ;
528534 if ( selectedSet . has ( normalizeKeyValue ( childKey ) ) ) {
529535 const props = element . props as any ;
@@ -698,7 +704,7 @@ export const FilterPicker = forwardRef(function FilterPicker<T extends object>(
698704 if ( sectionChild && typeof sectionChild === 'object' ) {
699705 const sectionElement = sectionChild as ReactElement ;
700706 if (
701- sectionElement . type === Item ||
707+ sectionElement . type === ReactAriaItem ||
702708 ( sectionElement . type as any ) ?. displayName === 'Item'
703709 ) {
704710 const clonedItem = cloneWithNormalizedKey ( sectionElement ) ;
@@ -895,7 +901,7 @@ export const FilterPicker = forwardRef(function FilterPicker<T extends object>(
895901 ) ;
896902 } ;
897903
898- const [ shouldUpdatePosition , setShouldUpdatePosition ] = useState ( false ) ;
904+ const [ shouldUpdatePosition , setShouldUpdatePosition ] = useState ( true ) ;
899905
900906 // The trigger is rendered as a function so we can access the dialog state
901907 const renderTrigger = ( state ) => {
@@ -943,8 +949,15 @@ export const FilterPicker = forwardRef(function FilterPicker<T extends object>(
943949 } ) ;
944950
945951 useEffect ( ( ) => {
946- // Disable the update of the position while the popover is open (with a delay) to avoid jumping
947- setShouldUpdatePosition ( ! state . isOpen ) ;
952+ // Allow initial positioning & flipping when opening, then lock placement after transition
953+ // Popover transition is ~120ms, give it a bit more time to finalize placement
954+ if ( state . isOpen ) {
955+ setShouldUpdatePosition ( true ) ;
956+ const id = window . setTimeout ( ( ) => setShouldUpdatePosition ( false ) , 160 ) ;
957+ return ( ) => window . clearTimeout ( id ) ;
958+ } else {
959+ setShouldUpdatePosition ( true ) ;
960+ }
948961 } , [ state . isOpen ] ) ;
949962
950963 // Clear button logic
@@ -971,6 +984,8 @@ export const FilterPicker = forwardRef(function FilterPicker<T extends object>(
971984
972985 triggerRef ?. current ?. focus ?.( ) ;
973986
987+ props . onClear ?.( ) ;
988+
974989 return false ;
975990 } ) ;
976991
@@ -1032,7 +1047,7 @@ export const FilterPicker = forwardRef(function FilterPicker<T extends object>(
10321047 placement = "bottom start"
10331048 styles = { triggerStyles }
10341049 shouldUpdatePosition = { shouldUpdatePosition }
1035- shouldFlip = { shouldFlip }
1050+ shouldFlip = { shouldFlip && shouldUpdatePosition }
10361051 isDismissable = { true }
10371052 shouldCloseOnInteractOutside = { ( el ) => {
10381053 const menuTriggerEl = el . closest ( '[data-popover-trigger]' ) ;
@@ -1207,7 +1222,7 @@ export const FilterPicker = forwardRef(function FilterPicker<T extends object>(
12071222 ) ;
12081223} ) as unknown as ( < T > (
12091224 props : CubeFilterPickerProps < T > & { ref ?: ForwardedRef < HTMLElement > } ,
1210- ) => ReactElement ) & { Item : typeof Item ; Section : typeof BaseSection } ;
1225+ ) => ReactElement ) & { Item : typeof ListBox . Item ; Section : typeof BaseSection } ;
12111226
12121227FilterPicker . Item = ListBox . Item ;
12131228
0 commit comments