Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[#137] Make ui_tabs accessible #139

Merged
merged 4 commits into from
Oct 23, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

## Unreleased

- Changed `ui_tabs` and `ui_tab_button` to follow accessibility guidelines. As a side effect the gap between the tabs is now a little smaller.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe worth mentioning what you wrote in the issue

replace the <ul> with a <div role="tablist">

hannahbit marked this conversation as resolved.
Show resolved Hide resolved

## v2.5.0 - 2024-09-25

- Switched bitstyles version comparisons from string comparisons to tuple comparisons, which will ensure correct output if bitstyles version ever contains a number above 9.
Expand Down Expand Up @@ -48,9 +50,9 @@ The `variant` attribute of the `Button` component is deprecated in bitstyles `v5

- Add `heading_class` option to `ui_section_title` to set classes on the heading
- `ui_dl_items` now aligns the items to the baseline (following the Bitstyles examples)
- Updated to bitstyles `v4.3.0`.
- Updated to bitstyles `v4.3.0`.

### Added
### Added

- Inputs now render a required label *. This can be configured via `required_label` config. If you do not want this new behaviour, define an empty component as required label.

Expand Down
96 changes: 37 additions & 59 deletions lib/bitstyles_phoenix/component/tabs.ex
Original file line number Diff line number Diff line change
Expand Up @@ -40,23 +40,17 @@ defmodule BitstylesPhoenix.Component.Tabs do
''',
'''
"""
<ul class="u-list-none u-flex u-flex-wrap u-items-end a-button--tab-container u-margin-m-bottom" role="tablist">
<li class="u-margin-s2-right">
<button type="button" class="a-button a-button--tab">
Foo
</button>
</li>
<li class="u-margin-s2-right">
<button type="button" class="a-button a-button--tab">
Bar
</button>
</li>
<li class="u-margin-s2-right">
<button type="button" class="a-button a-button--tab">
Baz
</button>
</li>
</ul>
<div class="u-flex u-flex-wrap u-items-end u-margin-m-bottom u-gap-s3" role="tablist">
<button type="button" class="a-button a-button--tab" role="tab">
Foo
</button>
<button type="button" class="a-button a-button--tab" role="tab">
Bar
</button>
<button type="button" class="a-button a-button--tab" role="tab">
Baz
</button>
</div>
"""
''',
transparent: false
Expand All @@ -76,23 +70,17 @@ defmodule BitstylesPhoenix.Component.Tabs do
''',
'''
"""
<ul class="u-list-none u-flex u-flex-wrap u-items-end a-button--tab-container u-margin-m-bottom" role="tablist">
<li class="u-margin-s2-right">
<button type="button" aria-selected="true" class="a-button a-button--tab">
Foo
</button>
</li>
<li class="u-margin-s2-right">
<button type="button" aria-selected="false" class="a-button a-button--tab">
Bar
</button>
</li>
<li class="u-margin-s2-right">
<button type="button" aria-selected="false" class="a-button a-button--tab">
Baz
</button>
</li>
</ul>
<div class="u-flex u-flex-wrap u-items-end u-margin-m-bottom u-gap-s3" role="tablist">
<button type="button" aria-selected="true" class="a-button a-button--tab" role="tab">
Foo
</button>
<button type="button" aria-selected="false" class="a-button a-button--tab" role="tab">
Bar
</button>
<button type="button" aria-selected="false" class="a-button a-button--tab" role="tab">
Baz
</button>
</div>
"""
''',
transparent: false
Expand All @@ -112,23 +100,17 @@ defmodule BitstylesPhoenix.Component.Tabs do
''',
'''
"""
<ul class="u-list-none u-flex u-flex-wrap u-items-end a-button--tab-container u-margin-m-bottom" role="tablist">
<li class="u-margin-s2-right">
<button type="button" aria-selected="true" class="a-button a-button--tab">
Foo
</button>
</li>
<li class="u-margin-s2-right">
<button type="button" aria-selected="false" class="a-button a-button--tab">
Bar
</button>
</li>
<li class="u-margin-s2-right">
<a href="#" aria-selected="false" class="a-button a-button--tab extra">
Baz
</a>
</li>
</ul>
<div class="u-flex u-flex-wrap u-items-end u-margin-m-bottom u-gap-s3" role="tablist">
<button type="button" aria-selected="true" class="a-button a-button--tab" role="tab">
Foo
</button>
<button type="button" aria-selected="false" class="a-button a-button--tab" role="tab">
Bar
</button>
<a href="#" aria-selected="false" class="a-button a-button--tab extra" role="tab">
Baz
</a>
</div>
"""
''',
transparent: false
Expand All @@ -137,27 +119,23 @@ defmodule BitstylesPhoenix.Component.Tabs do
def ui_tabs(assigns) do
class =
classnames([
"u-list-none u-flex u-flex-wrap u-items-end a-button--tab-container u-margin-m-bottom",
"u-flex u-flex-wrap u-items-end u-margin-m-bottom u-gap-s3",
assigns[:class]
])

extra = assigns_to_attributes(assigns, [:class, :tab, :active])
assigns = assign(assigns, class: class, extra: extra)

~H"""
<ul class={@class} role="tablist" {@extra}>
<div class={@class} role="tablist" {@extra}>
<%= for tab <- @tab do %>
<%= if Map.get(tab, :show, true) do %>
<li
class={classnames(["u-margin-s2-right"])}
>
<.ui_tab_button {button_options(tab, assigns[:active])}>
<%= render_slot(tab) %>
</.ui_tab_button>
</li>
<% end %>
<% end %>
</ul>
</div>
"""
end

Expand Down Expand Up @@ -193,7 +171,7 @@ defmodule BitstylesPhoenix.Component.Tabs do
assigns = assign(assigns, extra: Keyword.merge(extra, active))

~H"""
<.ui_button {@extra} color="tab" shape="tab">
<.ui_button {@extra} role="tab" color="tab" shape="tab">
<%= render_slot(@inner_block) %>
</.ui_button>
"""
Expand Down
Loading