+
+
+
+
+
+
+
1
+
2
+
4
+
`
+
+ it("switches tabs on click", () => {
+ html(tabs())
+ init()
+ click($("#t2"))
+
+ expect($("#t2").getAttribute("aria-selected")).toBe("true")
+ expect($("#t2").getAttribute("data-state")).toBe("active")
+ expect($("#t2").tabIndex).toBe(0)
+ expect($("#t1").getAttribute("aria-selected")).toBe("false")
+ expect($("#t1").tabIndex).toBe(-1)
+ expect($("#p2").classList.contains("hidden")).toBe(false)
+ expect($("#p2").getAttribute("data-state")).toBe("active")
+ expect($("#p1").classList.contains("hidden")).toBe(true)
+ expect($("#p1").classList.contains("active")).toBe(false)
+
+ click($("#t3"))
+ expect($("#t2").getAttribute("aria-selected")).toBe("true")
+ })
+
+ it("moves with the arrow keys, skipping disabled tabs", () => {
+ html(tabs())
+ init()
+ $("#t1").focus()
+
+ key($("#t1"), "ArrowRight")
+ expect(document.activeElement).toBe($("#t2"))
+ key($("#t2"), "ArrowRight")
+ expect(document.activeElement).toBe($("#t4"))
+ key($("#t4"), "ArrowRight")
+ expect(document.activeElement).toBe($("#t1"))
+ key($("#t1"), "ArrowLeft")
+ expect(document.activeElement).toBe($("#t4"))
+ key($("#t4"), "Home")
+ expect(document.activeElement).toBe($("#t1"))
+ key($("#t1"), "End")
+ expect(document.activeElement).toBe($("#t4"))
+ expect(key($("#t4"), "a").defaultPrevented).toBe(false)
+ })
+
+ it("reverses the arrow keys right to left", () => {
+ html(tabs("rtl"))
+ init()
+ key($("#t1"), "ArrowLeft")
+ expect($("#t2").getAttribute("aria-selected")).toBe("true")
+ key($("#t2"), "ArrowRight")
+ expect($("#t1").getAttribute("aria-selected")).toBe("true")
+ })
+
+ it("uses up and down for vertical tabs", () => {
+ html(tabs().replace('role="tablist"', 'role="tablist" aria-orientation="vertical"'))
+ init()
+ key($("#t1"), "ArrowDown")
+ expect($("#t2").getAttribute("aria-selected")).toBe("true")
+ key($("#t2"), "ArrowUp")
+ expect($("#t1").getAttribute("aria-selected")).toBe("true")
+ })
+
+ it("handles missing panels", () => {
+ html(`