Skip to content

Commit

Permalink
Use get for $root in GOVUKFrontendComponent
Browse files Browse the repository at this point in the history
Allows Typescript user to work around the lack of types
in GOVUKFrontend package, Typescript is not aware of $root
in components that extend GOVUKFrontendComponent

Co-authored-by: Romaric Pascal
<[email protected]>
  • Loading branch information
patrickpatrickpatrick committed Oct 10, 2024
1 parent 74c8102 commit 4dc6be9
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions packages/govuk-frontend/src/govuk/govuk-frontend-component.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,24 @@ export class GOVUKFrontendComponent {
*/
static elementType = HTMLElement

// allows Typescript user to work around the lack of types
// in GOVUKFrontend package, Typescript is not aware of $root
// in components that extend GOVUKFrontendComponent
/**
* Returns the root element of the component
*
* @protected
* @returns {RootElementType} - the root element of component
*/
get $root() {
return this._$root
}

/**
* @protected
* @type {RootElementType}
*/
$root
_$root

/**
* Constructs a new component, validating that GOV.UK Frontend is supported
Expand Down Expand Up @@ -51,7 +64,7 @@ export class GOVUKFrontendComponent {
expectedType: childConstructor.elementType.name
})
} else {
this.$root = /** @type {RootElementType} */ ($root)
this._$root = /** @type {RootElementType} */ ($root)
}

childConstructor.checkSupport()
Expand Down

0 comments on commit 4dc6be9

Please sign in to comment.