[deploy] Make profile settings save button sticky when modified (#9378)

* Make profile settings save button sticky when modified

* Replace querySelector with class selector, add newlines to end of files

* Make profile settings save button sticky when modified

* Replace querySelector with class selector, add newlines to end of files

* Add rspec test for sticky footer

* Move visit method to before block
This commit is contained in:
Emma Goto 2020-07-23 01:45:43 +10:00 committed by GitHub
parent 91c6541f57
commit f6ee0f20e2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 25 additions and 4 deletions

View file

@ -139,3 +139,9 @@ $input-width: 650px;
.crayons-notice--danger h3 {
color: var(--accent-danger-darker);
}
.sticky-save-footer {
position: -webkit-sticky; /* Safari */
position: sticky;
bottom: 0;
}

View file

@ -0,0 +1,6 @@
const form = document.querySelector('.edit_user');
form.addEventListener('change', () => {
const saveFooter = document.getElementsByClassName('save-footer');
saveFooter && saveFooter[0] && saveFooter[0].classList.add('sticky-save-footer');
});

View file

@ -1,4 +1,4 @@
<%= javascript_packs_with_chunks_tag "colorPreview", "validateFileInputs", defer: true %>
<%= javascript_packs_with_chunks_tag "colorPreview", "validateFileInputs", "stickySaveFooter", defer: true %>
<%= render "users/additional_authentication" %>
@ -186,7 +186,7 @@
</div>
</div>
<div class="mb-6 grid gap-6 p-6">
<div class="save-footer crayons-card mb-6 grid gap-6 p-6">
<%= f.hidden_field :tab, value: @tab %>
<div>
<button type="submit" class="crayons-btn">Save</button>

View file

@ -5,16 +5,25 @@ RSpec.describe "User edits their profile", type: :system do
before do
sign_in user
visit "/settings/profile"
end
describe "visiting /settings/profile" do
it "renders an error if the username contains spaces and thus is invalid" do
visit "/settings/profile"
fill_in "user[username]", with: "a b c"
click_button "Save"
expect(page).to have_text("Username is invalid")
end
it "makes the 'Save Button' footer sticky once a field is filled in", js: true do
expect(page).not_to have_css(".sticky-save-footer")
fill_in "user[website_url]", with: "example.com"
find("#user_website_url").native.send_keys :tab # this un-focuses the filled-in field
expect(page).to have_css(".sticky-save-footer")
end
end
end