alphagov / govuk-frontend

GOV.UK Frontend contains the code you need to start building a user interface for government platforms and services.
https://frontend.design-system.service.gov.uk/
MIT License
1.16k stars 319 forks source link

[Stretch] Investigate how to prevent component initialisation based on a condition #5225

Open romaricpascal opened 1 month ago

romaricpascal commented 1 month ago

What

Investigate how to prevent component initialisation based on a condition, like Analytics needing users to have accepted cookies on the Design System site.

Why

This would offer a consistent way to initialise components that require a little check before actually being initialised, without having to actually instantiate them.

Who needs to work on this

Developers

Who needs to review this

Developers

Done when

romaricpascal commented 1 week ago

This would provide a clear point for checking the presence of specific APIs, like in the Copy component of the Design System.

romaricpascal commented 13 hours ago

Having a separate method to check if specific APIs are supported overlaps a lot with isSupported, made @protected in #5323. We've decided to merge the two approaches and make checkSupport static and protected, which will allow it to:

Child classes overriding the method will be able to throw whatever Error they see fit when support is not available for the component, which: