Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
5 changes: 5 additions & 0 deletions .changeset/hungry-poems-shout.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@primer/view-components": patch
---

Reserve height as well as width in `.ToggleSwitch-statusIcon` so the switch doesn't jump when the loading spinner is shown
4 changes: 4 additions & 0 deletions app/components/primer/alpha/toggle_switch.pcss
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,11 @@

.ToggleSwitch-statusIcon {
display: flex;
flex: none;
align-items: center;
justify-content: center;
width: var(--base-size-16);
height: var(--base-size-16);
/* stylelint-disable-next-line primer/spacing */
margin-top: 0.063rem;
}
Expand Down
33 changes: 33 additions & 0 deletions test/system/alpha/toggle_switch_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,41 @@ def test_fetch_made_without_turbo
assert_equal "*/*", Primer::ViewComponents::ToggleSwitchController.last_request.headers["HTTP_ACCEPT"]
end

def test_switch_does_not_move_when_loading_spinner_is_shown
visit_preview(:small)

before_top = track_top

# Show the spinner the same way setLoadingState() does, without racing the request.
page.execute_script(
"document.querySelector(\"[data-target='toggle-switch.loadingSpinner']\").removeAttribute('hidden')"
)
Comment thread
gabrielhl marked this conversation as resolved.
Outdated
assert_selector("[data-target='toggle-switch.loadingSpinner']")

assert_in_delta before_top, track_top, 0.5
end

def test_switch_does_not_move_when_error_icon_is_shown
visit_preview(:small)

before_top = track_top

# Show the error icon the same way setErrorState() does. It's an <svg>, so it has no
# `hidden` IDL property and the attribute has to be removed directly.
page.execute_script(
"document.querySelector(\"[data-target='toggle-switch.errorIcon']\").removeAttribute('hidden')"
)
assert_selector("[data-target='toggle-switch.errorIcon']")

assert_in_delta before_top, track_top, 0.5
end

private

def track_top
evaluate_script("document.querySelector('.ToggleSwitch-track').getBoundingClientRect().top")
end

def wait_for_spinner
refute_selector("[data-target='toggle-switch.loadingSpinner']")
end
Expand Down
Loading