Skip to content

Commit

Permalink
fix(overlay): persist "host" in directive rendered Overlay content (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
Westbrook Johnson authored May 22, 2024
1 parent 39706da commit 5d189c2
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions packages/overlay/src/overlay-trigger-directive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,11 @@ OF ANY KIND, either express or implied. See the License for the specific languag
governing permissions and limitations under the License.
*/
import {
ElementPart,
type ElementPart,
nothing,
render,
TemplateResult,
type RenderOptions,
type TemplateResult,
} from '@spectrum-web-components/base';
import { directive } from '@spectrum-web-components/base/src/async-directive.js';
import { strategies } from './strategies.js';
Expand Down Expand Up @@ -41,6 +42,7 @@ export type OverlayTriggerOptions = {
};

export class OverlayTriggerDirective extends SlottableRequestDirective {
private host?: object;
private overlay!: AbstractOverlay;
private strategy!: ClickController | HoverController | LongpressController;

Expand Down Expand Up @@ -77,6 +79,7 @@ export class OverlayTriggerDirective extends SlottableRequestDirective {
};
this.insertionOptions = options?.insertionOptions;
this.template = template;
this.host = part.options?.host;
let newTarget = false;
const triggerInteraction = (options?.triggerInteraction ||
this.defaultOptions.triggerInteraction) as TriggerInteraction;
Expand Down Expand Up @@ -107,7 +110,15 @@ export class OverlayTriggerDirective extends SlottableRequestDirective {
if (event.target !== event.currentTarget) return;

const willRemoveSlottable = event.data === removeSlottableRequest;
render(willRemoveSlottable ? undefined : this.template(), this.overlay);
const options = {} as RenderOptions;
if (this.host) {
options.host = this.host;
}
render(
willRemoveSlottable ? undefined : this.template(),
this.overlay,
options
);

if (willRemoveSlottable) {
this.overlay.remove();
Expand Down

0 comments on commit 5d189c2

Please sign in to comment.