kopia lustrzana https://github.com/shoelace-style/shoelace
feat(sl-popup): Add contextElement property to VirtualElement interface (#1874)
rodzic
9b19c4c782
commit
6e288a80a3
|
@ -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
|
||||||
|
};
|
||||||
|
```
|
||||||
|
|
|
@ -10,10 +10,11 @@ import type { CSSResultGroup } from 'lit';
|
||||||
|
|
||||||
export interface VirtualElement {
|
export interface VirtualElement {
|
||||||
getBoundingClientRect: () => DOMRect;
|
getBoundingClientRect: () => DOMRect;
|
||||||
|
contextElement?: Element;
|
||||||
}
|
}
|
||||||
|
|
||||||
function isVirtualElement(e: unknown): e is VirtualElement {
|
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Ładowanie…
Reference in New Issue