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

Component wrapper documentation fixes #4499

Merged
merged 2 commits into from
Dec 13, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
href: "#other-examples",
text: "Other examples",
items: other_examples_links
} if @component_doc.other_examples.any?),
} if @component_doc.other_examples.any? or @component_doc.uses_component_wrapper_helper?),
].compact
%>
<%= render "govuk_publishing_components/components/contents_list", {
Expand Down Expand Up @@ -92,7 +92,7 @@
</div>
<% end %>

<% if @component_doc.other_examples.any? %>
<% if @component_doc.other_examples.any? or @component_doc.uses_component_wrapper_helper? %>
<div class="examples">
<h2 class="component-doc-h2" id="other-examples">Other examples</h2>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@
component_helper.set_id(id)
component_helper.add_class("gem-c-contextual-guidance")
component_helper.add_data_attribute({ module: "contextual-guidance" })

%>

<%= tag.div(**component_helper.all_attributes) do %>
<%= tag.div class: "govuk-grid-row" do %>
<%= tag.div class: "govuk-grid-column-two-thirds" do %>
Expand Down
5 changes: 5 additions & 0 deletions docs/component-wrapper-helper.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ These options can be passed to any component that uses the component wrapper.
- `role` - accepts a space separated string of roles
- `lang` - accepts a language attribute value
- `open` - accepts an open attribute value (true or false)
- `hidden` - accepts an empty string, 'hidden', or 'until-found'
- `tabindex` - accepts an integer. The integer can also be passed as a string.
- `dir` - accepts 'rtl', 'ltr', or 'auto'.

To prevent breaking [component isolation](https://github.com/alphagov/govuk_publishing_components/blob/main/docs/component_principles.md#a-component-is-isolated-when), passed classes should only be used for JavaScript hooks and not styling. All component styling should be included only in the component itself. Any passed classes should be prefixed with `js-`. To allow for extending this option, classes prefixed with `gem-c-`, `govuk-`, `app-c-`, `brand--`, or `brand__` are also permitted, as well as an exact match of `direction-rtl`, but these classes should only be used within the component and not passed to it.

Expand Down Expand Up @@ -73,6 +76,8 @@ The component wrapper includes several methods to make managing options easier,
component_helper.add_role("button") # works like 'add_class'
component_helper.set_lang("en") # works like 'set_id' (can only have one lang)
component_helper.set_open(true) # can pass true or false
component_helper.set_tabindex(1)
component_helper.set_dir("rtl")
%>
<%= tag.div(**component_helper.all_attributes) do %>
component content
Expand Down
Loading