A11Y: improve setting focus to a post (#24786)

See https://github.com/discourse/discourse/pull/23367 for implementation details.
This commit is contained in:
Penar Musaraj
2023-12-08 11:06:21 -05:00
committed by GitHub
parent 27144f188c
commit 6dc5fe0c83
8 changed files with 74 additions and 44 deletions

View File

@@ -23,6 +23,10 @@ describe "Topic list focus", type: :system do
)&.to_i
end
def focussed_post_id
page.evaluate_script("document.activeElement.closest('.onscreen-post')?.dataset.postId")&.to_i
end
it "refocusses last clicked topic when going back to topic list" do
visit("/latest")
expect(page).to have_css("body.navigation-topics")
@@ -103,4 +107,17 @@ describe "Topic list focus", type: :system do
expect(page).to have_css("body.navigation-topics")
expect(focussed_topic_id).to eq(oldest_topic.id)
end
it "sets focus to the last post when navigating to a topic" do
extra_posts = Fabricate.times(5, :post, topic: topics[2])
visit("/latest")
discovery.topic_list.visit_topic_last_reply_via_keyboard(topics[2])
# send Tab key twice, the first event serves to focus the window
find("body").native.send_keys :tab
find("body").native.send_keys :tab
expect(focussed_post_id).to eq(topics[2].posts.last.id)
end
end