Problem/Motivation
I've been testing out some of the components provided by Radix (these have been great as an intro to SDC), and ran into an issue when trying to set up the carousel component, related to the boolean values for show_carousel_control, show_carousel_indicators, and show_carousel_caption.
Steps to reproduce
Render a radix:carousel component without defining one of the 3 mentioned properties, like show_carousel_control or set one of those values to false.
This should produce:
Drupal\Core\Render\Component\Exception\InvalidComponentException: [radix:carousel/show_carousel_control] String value found, but a boolean or an object is required. The provided value is: "true". in Drupal\Core\Theme\Component\ComponentValidator->validateProps() (line 232 of core/lib/Drupal/Core/Theme/Component/ComponentValidator.php).
Proposed resolution
Switch string default values to booleans in carousel.twig to avoid this error, like:
{% set show_carousel_control = show_carousel_control|default('true') %}
to
{% set show_carousel_control = show_carousel_control|default(true) %}
But then it turns out that this doesn't quite work as expected and passing a value of false will result in the default value of true still being used. From https://twig.symfony.com/doc/3.x/filters/default.html
Using the default filter on a boolean variable might trigger unexpected behavior, as false is treated as an empty value. Consider using ?? instead
So a working fix could be like:
{% set show_carousel_control = show_carousel_control ?? true %}
So any components where |default('true') or |default('false') are used (looks like only carousel and offcanvas) should have strings values converted to boolean.
Then any component with |default(true) or |default(false) should be converted to use ?? instead of |default (looks like modal, progress, toasts, carousel, dropdown, form-element--readiocheckbox, list-group).