Files
threshold-ui/ui/admin/app/components/breadcrumbs/container/index.js
T
hashicorp-copywrite[bot]andZhihe Li c548c381bf [COMPLIANCE] Add Copyright and License Headers (#1966)
Co-authored-by: hashicorp-copywrite[bot] <110428419+hashicorp-copywrite[bot]@users.noreply.github.com>
Co-authored-by: Zhihe Li <zhihe.li@hashicorp.com>
2023-10-24 14:31:07 -04:00

38 lines
1016 B
JavaScript

/**
* Copyright (c) HashiCorp, Inc.
* SPDX-License-Identifier: MPL-2.0
*/
import Component from '@glimmer/component';
import { inject as service } from '@ember/service';
import { action } from '@ember/object';
/*
The `containers` property from the `breadcrumbsService` is tracked
so registering or unregistering a container will cause the DOM
to re-render a container with the correct breadcrumbs.
*/
export default class BreadcrumbsContainerComponent extends Component {
@service('breadcrumbs') breadcrumbsService;
container = null;
@action
registerContainer(element) {
// A child `ol` is rendered in the Hds::Breadcrumb container and this is
// the element that the in-element helper should drop breadcrumbs into.
this.container = {
element: element.querySelector('ol'),
};
this.breadcrumbsService.registerContainer(this.container);
}
willDestroy() {
super.willDestroy(...arguments);
this.breadcrumbsService.unregisterContainer(this.container);
}
}