Skip to content

Commit 38410c5

Browse files
committed
fix: Remove redundant button tag logic and dependency on deprecated schema
1 parent b511a05 commit 38410c5

File tree

1 file changed

+9
-13
lines changed

1 file changed

+9
-13
lines changed

packages/components/bolt-button/src/button.twig

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,18 @@
2525
{% set border_radius = "full" %}
2626
{% endif %}
2727

28+
{# DEPRECATED. Use the `type` property for a reset or submit button. Tag is determined automatically based on whether you pass a url. #}
29+
{% if tag in ["reset", "submit"] %}
30+
{% set type = type|default(tag) %}
31+
{% endif %}
32+
2833
{# Set up checks to validate that the component's prop values are allowed, based on the component's schema #}
2934
{% set size_options = schema.properties.size.enum %}
3035
{% set style_options = schema.properties.style.enum %}
3136
{% set width_options = schema.properties.width.enum %}
3237
{% set border_radius_options = schema.properties.border_radius.enum %}
3338
{% set align_options = schema.properties.align.enum %}
3439
{% set transform_options = schema.properties.transform.enum %}
35-
{% set tag_options = schema.properties.tag.enum %}
3640
{% set icon_positions = schema.properties.icon.properties.position.enum %}
3741
{% set iconOnly_options = schema.properties.iconOnly.enum %}
3842

@@ -43,13 +47,9 @@
4347
{% set border_radius = border_radius in border_radius_options ? border_radius : schema.properties.border_radius.default %}
4448
{% set align = align in align_options ? align : schema.properties.align.default %}
4549
{% set transform = transform in transform_options ? transform : schema.properties.transform.default %}
46-
{% set tag = tag in tag_options ? tag : schema.properties.tag.default %}
4750
{% set iconOnly = iconOnly is sameas(true) or iconOnly is sameas(false) ? iconOnly : scheuma.properties.iconOnly.default %}
4851

49-
{% if tag == "submit" or type == "submit" %}
50-
{% set tag = "button" %}
51-
{% set inner_attributes = inner_attributes.setAttribute("type", "submit") %}
52-
{% elseif tag == "link" or tag == "a" or url != null %}
52+
{% if url != null %}
5353
{% set tag = "a" %}
5454
{% if disabled %}
5555
{% set inner_attributes = inner_attributes.setAttribute("aria-disabled", "true") %}
@@ -61,14 +61,10 @@
6161
{% if attributes.target %}
6262
{% set inner_attributes = inner_attributes.setAttribute("target", attributes.target) %}
6363
{% endif %}
64-
{% elseif tag == "reset" or type == "reset" %}
64+
{% else %}
6565
{% set tag = "button" %}
66-
{% set inner_attributes = inner_attributes.setAttribute("type", "reset") %}
67-
{% endif %}
68-
69-
{# shorthand for manually setting HTML attribute `type` such as submit or reset #}
70-
{% if type %}
71-
{% set inner_attributes = inner_attributes.setAttribute("type", type) %}
66+
{% set type = type in type_options ? type : "button" %}
67+
{% set inner_attributes = inner_attributes.setAttribute("type", type ) %}
7268
{% endif %}
7369

7470
{# Array of classes based on the defined + default props #}

0 commit comments

Comments
 (0)