Skip to content

Commit

Permalink
fix(types): add missing ref prop to Portal (#1031)
Browse files Browse the repository at this point in the history
- Adds the missing `ref` prop to `<Portal>`.
- If `isSVG`, the element in `ref` is `SVGGElement`, otherwise it is `HTMLDivElement`.
- If `useShadow`, the element in `ref` has a non-null `shadowRoot` property.
- `ref` is unused when mounting to `document.head`, however there is no way to detect this as `HTMLHeadElement` is typed identically to `HTMLElement`.

See https://tsplay.dev/mb0P2w.
  • Loading branch information
otonashixav committed Jun 2, 2022
1 parent 80abe09 commit c23f730
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions packages/solid/web/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,16 @@ export const hydrate: typeof hydrateCore = (...args) => {
*
* @description https://www.solidjs.com/docs/latest/api#%3Cportal%3E
*/
export function Portal(props: {
export function Portal<T extends boolean = false, S extends boolean = false>(props: {
mount?: Node;
useShadow?: boolean;
isSVG?: boolean;
useShadow?: T;
isSVG?: S;
ref?:
| (S extends true ? SVGGElement : HTMLDivElement)
| ((
el: (T extends true ? { readonly shadowRoot: ShadowRoot } : {}) &
(S extends true ? SVGGElement : HTMLDivElement)
) => void);
children: JSX.Element;
}) {
const { useShadow } = props,
Expand Down

0 comments on commit c23f730

Please sign in to comment.