Skip to content

Commit

Permalink
Refactor(web-twig): Mark the id prop in form fields as required sta…
Browse files Browse the repository at this point in the history
…rting from next major version

As of now, some form field components require the `id` prop and some do not.

An ID is necessary to:

1. connect the input to its label,
2. connect the input the its helper texts and validation texts (coming soon).

Last but not least, a consistent approach to API is expected from all form field components.
  • Loading branch information
adamkudrna committed Aug 15, 2023
1 parent 4edef48 commit 28cfcf1
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,11 @@
{%- set _mainPropsWithoutId = props | filter((value, prop) => prop is not same as('id')) -%}
{%- set _allowedInputAttributes = [ 'autocomplete' ] -%}

{# Deprecations #}
{% if not _id %}
{% deprecated 'Checkbox: The "id" property will be required starting from the next major version.' %}
{% endif %}

<label for="{{ _id }}" {{ mainProps(_mainPropsWithoutId) }} {{ styleProp(_styleProps) }} {{ classProp(_classNames) }}>
<input
{{ inputProps(props, _allowedInputAttributes, _inputProps) }}
Expand Down
5 changes: 5 additions & 0 deletions packages/web-twig/src/Resources/components/Radio/Radio.twig
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@
{%- set _mainPropsWithoutId = props | filter((value, prop) => prop is not same as('id')) -%}
{%- set _allowedInputAttributes = [ 'autocomplete' ] -%}

{# Deprecations #}
{% if not _id %}
{% deprecated 'Radio: The "id" property will be required starting from the next major version.' %}
{% endif %}

<label {{ _labelForAttr | raw }} {{ mainProps(_mainPropsWithoutId) }} {{ styleProp(_styleProps) }} {{ classProp(_classNames) }}>
<input
{{ inputProps(props, _allowedInputAttributes, _inputProps) }}
Expand Down
5 changes: 5 additions & 0 deletions packages/web-twig/src/Resources/components/Select/Select.twig
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@
{%- set _labelClassNames = [ _labelClassName, _labelHiddenClassName, _labelRequiredClassName ] -%}
{%- set _mainPropsWithoutId = props | filter((value, prop) => prop is not same as('id')) -%}

{# Deprecations #}
{% if not _id %}
{% deprecated 'Select: The "id" property will be required from the next major version.' %}
{% endif %}

<div {{ mainProps(_mainPropsWithoutId) }} {{ styleProp(_styleProps) }} {{ classProp(_classNames) }}>
<label for="{{ _id }}" {{ classProp(_labelClassNames) }}>
{%- if _unsafeLabel %}{{ _unsafeLabel | raw }}{% else %}{{ _label }}{% endif -%}
Expand Down

0 comments on commit 28cfcf1

Please sign in to comment.