-
-
Notifications
You must be signed in to change notification settings - Fork 269
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
✨ Password: add reveal property (#3341)
* ✨ Password: add reveal property * ⬆️ Upgrade registry for on package * ♻️ Refactor password component using Avo helpers * 🧪 Password reveal: add system test * 🚚 Rename password reveal to revealable
- Loading branch information
Showing
8 changed files
with
62 additions
and
10 deletions.
There are no files selected for viewing
30 changes: 21 additions & 9 deletions
30
app/components/avo/fields/password_field/edit_component.html.erb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,24 @@ | ||
<%= field_wrapper **field_wrapper_args do %> | ||
<%= @form.password_field @field.id, | ||
value: @field.value, | ||
class: classes("w-full"), | ||
data: @field.get_html(:data, view: view, element: :input), | ||
disabled: disabled?, | ||
placeholder: @field.placeholder, | ||
style: @field.get_html(:style, view: view, element: :input), | ||
autocomplete: @field.autocomplete, | ||
autofocus: @autofocus | ||
<div class="relative" data-controller="<%= @field.revealable ? 'password-visibility' : nil %>"> | ||
<%= @form.password_field @field.id, | ||
value: @field.value, | ||
class: classes("w-full"), | ||
data: @field.get_html(:data, view: view, element: :input).merge(password_visibility_target: "input"), | ||
disabled: disabled?, | ||
placeholder: @field.placeholder, | ||
style: @field.get_html(:style, view: view, element: :input), | ||
autocomplete: @field.autocomplete, | ||
autofocus: @autofocus | ||
%> | ||
|
||
<% if @field.revealable %> | ||
<button data-action="password-visibility#toggle" type="button" class="text-gray-500 absolute inset-y-0 right-0 pr-3 flex items-center cursor-pointer"> | ||
<!-- Heroicon name: outline/eye --> | ||
<%= helpers.svg('heroicons/outline/eye', class: "size-6", data: { 'password-visibility-target': 'icon' }) %> | ||
|
||
<!-- Heroicon name: outline/eye-off --> | ||
<%= helpers.svg('heroicons/outline/eye-off', class: "size-6 hidden", data: { 'password-visibility-target': 'icon' }) %> | ||
</button> | ||
<% end %> | ||
</div> | ||
<% end %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
require "rails_helper" | ||
|
||
RSpec.describe "PasswordField", type: :system do | ||
describe "revealable true" do | ||
context "create" do | ||
it "password revealable button is toggling" do | ||
visit "/admin/resources/users/new" | ||
|
||
expect(page).to have_field type: "password", id: "user_password_confirmation" | ||
find("[data-action='password-visibility#toggle']").click | ||
expect(page).to have_field type: "text", id: "user_password_confirmation" | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters