feat(sl-popup): Add contextElement property to VirtualElement interface (#1874)

pull/1879/head
stefanholzapfel 2024-02-20 19:44:53 +01:00 zatwierdzone przez GitHub
rodzic 9b19c4c782
commit 6e288a80a3
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: B5690EEEBB952194
2 zmienionych plików z 14 dodań i 1 usunięć

Wyświetl plik

@ -1839,3 +1839,15 @@ const App = () => {
);
};
```
Sometimes the `getBoundingClientRects` might be derived from a real element. In this case provide the anchor element as context to ensure clipping and position updates for the popup work well.
```ts
const virtualElement = {
getBoundingClientRect() {
// ...
return { width, height, x, y, top, left, right, bottom };
},
contextElement: anchorElement
};
```

Wyświetl plik

@ -10,10 +10,11 @@ import type { CSSResultGroup } from 'lit';
export interface VirtualElement {
getBoundingClientRect: () => DOMRect;
contextElement?: Element;
}
function isVirtualElement(e: unknown): e is VirtualElement {
return e !== null && typeof e === 'object' && 'getBoundingClientRect' in e;
return e !== null && typeof e === 'object' && 'getBoundingClientRect' in e && ('contextElement' in e ? e instanceof Element : true);
}
/**