Skip to content

Commit

Permalink
Allow autofocus on inputs
Browse files Browse the repository at this point in the history
This attribute will be used for the login page to ease the authentication process. It shouldn't be used without user research to back this behaviour.
  • Loading branch information
alex-ju committed Oct 1, 2018
1 parent cf1bcef commit 46ef235
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 5 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
* You can now use `GovukPublishingComponents::AppHelpers::Environment.current_acceptance_environment` to get the current environment, for use in the admin layout components (PR #548)
* Update GOV.UK Frontend from 1.2.0 to 2.1.0 and manage breaking changes (PR #545)
* Add navigation and meta links to footer component (PR #550)

* Allow autofocus on input component (PR #552)

## 11.0.0

Expand Down
10 changes: 6 additions & 4 deletions app/views/govuk_publishing_components/components/_input.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
label ||= nil
hint ||= nil
error_message ||= nil
autofocus ||= nil
tabindex ||= nil
hint_id = "hint-#{SecureRandom.hex(4)}" if hint
error_message_id = "error-message-#{SecureRandom.hex(4)}" if error_message

Expand Down Expand Up @@ -48,16 +50,16 @@
} %>
<% end %>

<%= text_field_tag name,
value,
{
<%= tag.input name: name,
value: value,
class: css_classes,
id: id,
type: type,
data: data,
tabindex: tabindex,
autofocus: autofocus,
aria: {
describedby: aria_described_by
}
}
%>
<% end %>
Original file line number Diff line number Diff line change
Expand Up @@ -56,3 +56,10 @@ examples:
text: "Search for"
name: "name"
value: "moose"
autofocused:
data:
label:
text: "Username"
name: "username"
autofocus: true
tabindex: 0
11 changes: 11 additions & 0 deletions spec/components/input_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,17 @@ def component_name
assert_select ".govuk-input[data-module='contextual-guidance']"
end

it "renders autofocused input" do
render_component(
label: { text: "Username" },
name: "username",
autofocus: true,
tabindex: 0
)

assert_select ".govuk-input[autofocus][tabindex='0']"
end

context "when a hint is provided" do
before do
render_component(
Expand Down

0 comments on commit 46ef235

Please sign in to comment.