Skip to content

Commit 2168b55

Browse files
committed
fix(popover): simplify Popover type to make ts happy
1 parent 0d8eafa commit 2168b55

File tree

1 file changed

+18
-18
lines changed
  • packages/kit-headless/src/components/popover

1 file changed

+18
-18
lines changed

packages/kit-headless/src/components/popover/popover.tsx

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4,29 +4,29 @@ import { PopoverImpl } from './popover-impl';
44
import { PopoverImplProps } from './popover-impl';
55
import { FloatingProps } from './floating';
66

7-
type PopoverProps = PopoverImplProps & ({ floating?: true } & FloatingProps);
7+
// TODO: improve the type so that it only includes FloatingProps when floating is true.
8+
type PopoverProps = PopoverImplProps & { floating?: boolean } & FloatingProps;
89

910
/* This component determines whether the popover needs floating behavior, a common example where it doesn't, would be a toast. */
10-
export const Popover = component$<PopoverProps>(
11-
({ floating, anchorRef, ref, ...props }) => {
12-
if (floating) {
13-
if (!anchorRef) {
14-
throw new Error(
15-
'Qwik UI Popover: anchorRef is required on the popover when floating is true',
16-
);
17-
}
18-
19-
return (
20-
<FloatingPopover ref={ref} anchorRef={anchorRef} {...props}>
21-
<Slot />
22-
</FloatingPopover>
11+
export const Popover = component$<PopoverProps>((props) => {
12+
if (props.floating) {
13+
const { ref, anchorRef, ...rest } = props;
14+
if (!anchorRef) {
15+
throw new Error(
16+
'Qwik UI Popover: anchorRef is required on the popover when floating is true',
2317
);
2418
}
2519

2620
return (
27-
<PopoverImpl {...props}>
21+
<FloatingPopover ref={ref} anchorRef={anchorRef} {...rest}>
2822
<Slot />
29-
</PopoverImpl>
23+
</FloatingPopover>
3024
);
31-
},
32-
);
25+
}
26+
27+
return (
28+
<PopoverImpl {...props}>
29+
<Slot />
30+
</PopoverImpl>
31+
);
32+
});

0 commit comments

Comments
 (0)