@appica/ui-react 1.3.1 → 1.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -10,7 +10,7 @@ export { Breadcrumb, BreadcrumbEllipsis, BreadcrumbItem, BreadcrumbLink, Breadcr
10
10
  export { ButtonGroup } from './components/button-group/button-group.js';
11
11
  export { Calendar } from './components/calendar/calendar.js';
12
12
  export { Card, CardDescription, CardFooter, CardHeader, CardMedia, CardTitle } from './components/card/card.js';
13
- export { Carousel, CarouselContent, CarouselNext, CarouselPagination, CarouselPrev, CarouselProgress, CarouselSlide, CarouselThumb, CarouselThumbs, useCarousel, useLinkedCarousels } from './components/carousel/carousel.js';
13
+ export { Carousel, CarouselContent, CarouselNext, CarouselPagination, CarouselPlayToggle, CarouselPrev, CarouselProgress, CarouselSlide, CarouselThumb, CarouselThumbs, useCarousel, useLinkedCarousels } from './components/carousel/carousel.js';
14
14
  export { Checkbox } from './components/checkbox/checkbox.js';
15
15
  export { CheckboxGroup } from './components/checkbox-group/checkbox-group.js';
16
16
  export { Chip, ChipGroup } from './components/chip/chip.js';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@appica/ui-react",
3
- "version": "1.3.1",
3
+ "version": "1.4.0",
4
4
  "description": "Appica UI components library for React applications",
5
5
  "license": "MIT",
6
6
  "author": "Appica UI",
@@ -69,7 +69,7 @@ vi.mock('embla-carousel-accessibility', () => ({
69
69
  default: (options?: object) => ({ name: 'accessibility', options: options ?? {}, init: () => {} }),
70
70
  }))
71
71
  vi.mock('embla-carousel-autoplay', () => ({
72
- default: () => ({ name: 'autoplay', options: {}, init: () => {} }),
72
+ default: (options?: object) => ({ name: 'autoplay', options: options ?? {}, init: () => {} }),
73
73
  }))
74
74
  vi.mock('embla-carousel-auto-scroll', () => ({
75
75
  default: () => ({ name: 'autoScroll', options: {}, init: () => {} }),
@@ -96,6 +96,7 @@ import {
96
96
  CarouselThumb,
97
97
  CarouselPrev,
98
98
  CarouselNext,
99
+ CarouselPlayToggle,
99
100
  CarouselPagination,
100
101
  CarouselProgress,
101
102
  useCarousel,
@@ -137,14 +138,17 @@ function mockDomSlides() {
137
138
  }
138
139
 
139
140
  /** A stand-in for the Autoplay plugin that reports play and stop through the stub's events. */
140
- function mockAutoplay() {
141
+ function mockAutoplay(options: object = {}) {
141
142
  let playing = false
142
143
  const autoplay = {
143
- options: { delay: 4000 },
144
+ options: { delay: 4000, ...options },
144
145
  isPlaying: vi.fn(() => playing),
145
146
  play: vi.fn(() => {
146
- playing = true
147
- dispatch('autoplay:play')
147
+ if (!playing) {
148
+ playing = true
149
+ dispatch('autoplay:play')
150
+ }
151
+ dispatch('autoplay:timerset')
148
152
  }),
149
153
  stop: vi.fn(() => {
150
154
  if (!playing) return
@@ -157,6 +161,27 @@ function mockAutoplay() {
157
161
  return autoplay
158
162
  }
159
163
 
164
+ /** A stand-in for the Auto Scroll plugin, in the same shape as `mockAutoplay`. */
165
+ function mockAutoScroll() {
166
+ let playing = false
167
+ const autoScroll = {
168
+ options: {},
169
+ isPlaying: vi.fn(() => playing),
170
+ play: vi.fn(() => {
171
+ if (playing) return
172
+ playing = true
173
+ dispatch('autoscroll:play')
174
+ }),
175
+ stop: vi.fn(() => {
176
+ if (!playing) return
177
+ playing = false
178
+ dispatch('autoscroll:stop')
179
+ }),
180
+ }
181
+ stubApi.plugins.mockReturnValue({ autoScroll })
182
+ return autoScroll
183
+ }
184
+
160
185
  function Basic(props?: Partial<CarouselProps>) {
161
186
  return (
162
187
  <Carousel {...props}>
@@ -994,7 +1019,8 @@ describe('Carousel autoplay', () => {
994
1019
  expect(autoplay.play).toHaveBeenCalledTimes(2)
995
1020
  })
996
1021
 
997
- it('pauses while focus is inside and resumes once it leaves the carousel', () => {
1022
+ it('pauses while keyboard focus is inside and resumes once it leaves the carousel', async () => {
1023
+ const user = userEvent.setup()
998
1024
  const autoplay = mockAutoplay()
999
1025
  render(
1000
1026
  <>
@@ -1002,15 +1028,77 @@ describe('Carousel autoplay', () => {
1002
1028
  <button type="button">Outside</button>
1003
1029
  </>,
1004
1030
  )
1005
- act(() => screen.getByRole('button', { name: 'Next slide' }).focus())
1031
+ await user.tab()
1032
+ expect(screen.getByRole('button', { name: 'Previous slide' })).toHaveFocus()
1006
1033
  expect(autoplay.isPlaying()).toBe(false)
1007
- act(() => screen.getByRole('button', { name: 'Previous slide' }).focus())
1034
+ await user.tab()
1035
+ expect(screen.getByRole('button', { name: 'Next slide' })).toHaveFocus()
1008
1036
  expect(autoplay.isPlaying()).toBe(false)
1009
1037
  act(() => screen.getByRole('button', { name: 'Outside' }).focus())
1010
1038
  expect(autoplay.isPlaying()).toBe(true)
1011
1039
  })
1012
1040
 
1013
- it('waits for both the pointer and focus to leave', () => {
1041
+ it('keeps playing after a mouse click on an arrow, and pauses once Tab lands on it', async () => {
1042
+ const user = userEvent.setup()
1043
+ const autoplay = mockAutoplay()
1044
+ render(
1045
+ <>
1046
+ <button type="button">Outside</button>
1047
+ <Basic autoplay />
1048
+ </>,
1049
+ )
1050
+ const next = screen.getByRole('button', { name: 'Next slide' })
1051
+ await user.click(next)
1052
+ expect(autoplay.isPlaying()).toBe(false)
1053
+ await user.unhover(next)
1054
+ expect(next).toHaveFocus()
1055
+ expect(autoplay.isPlaying()).toBe(true)
1056
+
1057
+ act(() => screen.getByRole('button', { name: 'Outside' }).focus())
1058
+ await user.tab()
1059
+ await user.tab()
1060
+ expect(next).toHaveFocus()
1061
+ expect(autoplay.isPlaying()).toBe(false)
1062
+ })
1063
+
1064
+ it('hands rotation back when a mouse click follows keyboard focus inside', async () => {
1065
+ const user = userEvent.setup()
1066
+ const autoplay = mockAutoplay()
1067
+ render(<Basic autoplay={{ pauseOnHover: false }} />)
1068
+ await user.tab()
1069
+ expect(autoplay.isPlaying()).toBe(false)
1070
+ await user.click(screen.getByRole('button', { name: 'Next slide' }))
1071
+ expect(autoplay.isPlaying()).toBe(true)
1072
+ })
1073
+
1074
+ it('starts again with mouse focus still inside when reduced motion turns off', async () => {
1075
+ const user = userEvent.setup()
1076
+ const autoplay = mockAutoplay()
1077
+ const { rerender } = render(
1078
+ <ReducedMotionProvider>
1079
+ <Basic autoplay />
1080
+ </ReducedMotionProvider>,
1081
+ )
1082
+ const next = screen.getByRole('button', { name: 'Next slide' })
1083
+ await user.click(next)
1084
+ await user.unhover(next)
1085
+ expect(next).toHaveFocus()
1086
+ rerender(
1087
+ <ReducedMotionProvider disableAnimations>
1088
+ <Basic autoplay />
1089
+ </ReducedMotionProvider>,
1090
+ )
1091
+ expect(autoplay.isPlaying()).toBe(false)
1092
+ rerender(
1093
+ <ReducedMotionProvider>
1094
+ <Basic autoplay />
1095
+ </ReducedMotionProvider>,
1096
+ )
1097
+ expect(autoplay.isPlaying()).toBe(true)
1098
+ })
1099
+
1100
+ it('waits for both the pointer and focus to leave', async () => {
1101
+ const user = userEvent.setup()
1014
1102
  const autoplay = mockAutoplay()
1015
1103
  const { container } = render(
1016
1104
  <>
@@ -1019,13 +1107,46 @@ describe('Carousel autoplay', () => {
1019
1107
  </>,
1020
1108
  )
1021
1109
  fireEvent.pointerEnter(root(container))
1022
- act(() => screen.getByRole('button', { name: 'Next slide' }).focus())
1110
+ await user.tab()
1023
1111
  fireEvent.pointerLeave(root(container))
1024
1112
  expect(autoplay.isPlaying()).toBe(false)
1025
1113
  act(() => screen.getByRole('button', { name: 'Outside' }).focus())
1026
1114
  expect(autoplay.isPlaying()).toBe(true)
1027
1115
  })
1028
1116
 
1117
+ it('keeps playing while hovered with pauseOnHover: false', async () => {
1118
+ const user = userEvent.setup()
1119
+ const autoplay = mockAutoplay()
1120
+ const { container } = render(<Basic autoplay={{ pauseOnHover: false }} />)
1121
+ fireEvent.pointerEnter(root(container))
1122
+ expect(autoplay.isPlaying()).toBe(true)
1123
+ await user.tab()
1124
+ expect(autoplay.isPlaying()).toBe(false)
1125
+ })
1126
+
1127
+ it('keeps playing with keyboard focus inside with pauseOnFocus: false', async () => {
1128
+ const user = userEvent.setup()
1129
+ const autoplay = mockAutoplay()
1130
+ const { container } = render(<Basic autoplay={{ pauseOnFocus: false }} />)
1131
+ await user.tab()
1132
+ expect(screen.getByRole('button', { name: 'Previous slide' })).toHaveFocus()
1133
+ expect(autoplay.isPlaying()).toBe(true)
1134
+ fireEvent.pointerEnter(root(container))
1135
+ expect(autoplay.isPlaying()).toBe(false)
1136
+ })
1137
+
1138
+ it('keeps pauseOnHover and pauseOnFocus away from the Embla plugin', () => {
1139
+ render(<Basic autoplay={{ delay: 3000, resumeAfter: 1000, pauseOnHover: false, pauseOnFocus: false }} />)
1140
+ const plugins = (useEmblaCarousel as unknown as ReturnType<typeof vi.fn>).mock.calls.at(-1)?.[1] as {
1141
+ name: string
1142
+ options: object
1143
+ }[]
1144
+ expect(plugins.find((plugin) => plugin.name === 'autoplay')?.options).toEqual({
1145
+ delay: 3000,
1146
+ defaultInteraction: false,
1147
+ })
1148
+ })
1149
+
1029
1150
  it('keeps a pointerdown stop after the pointer leaves, without resumeAfter', () => {
1030
1151
  const autoplay = mockAutoplay()
1031
1152
  const { container } = render(<Basic autoplay />)
@@ -1036,23 +1157,24 @@ describe('Carousel autoplay', () => {
1036
1157
  expect(autoplay.play).toHaveBeenCalledTimes(1)
1037
1158
  })
1038
1159
 
1039
- it('holds the resumeAfter restart while hovered or focused', () => {
1160
+ it('holds the resumeAfter restart while hovered or focused', async () => {
1161
+ const user = userEvent.setup()
1162
+ const autoplay = mockAutoplay({ defaultInteraction: false })
1163
+ const { container } = render(
1164
+ <>
1165
+ <Basic autoplay={{ resumeAfter: 1000 }} />
1166
+ <button type="button">Outside</button>
1167
+ </>,
1168
+ )
1169
+ await user.tab()
1040
1170
  vi.useFakeTimers({ toFake: ['setTimeout', 'clearTimeout'] })
1041
1171
  try {
1042
- const autoplay = mockAutoplay()
1043
- const { container } = render(
1044
- <>
1045
- <Basic autoplay={{ resumeAfter: 1000 }} />
1046
- <button type="button">Outside</button>
1047
- </>,
1048
- )
1049
1172
  fireEvent.pointerEnter(root(container))
1050
1173
  emit('pointerdown')
1051
1174
  emit('autoplay:interaction', { detail: { interaction: 'pointerdown' } })
1052
1175
  act(() => vi.advanceTimersByTime(1000))
1053
1176
  expect(autoplay.isPlaying()).toBe(false)
1054
1177
 
1055
- act(() => screen.getByRole('button', { name: 'Next slide' }).focus())
1056
1178
  fireEvent.pointerLeave(root(container))
1057
1179
  expect(autoplay.isPlaying()).toBe(false)
1058
1180
 
@@ -1063,10 +1185,29 @@ describe('Carousel autoplay', () => {
1063
1185
  }
1064
1186
  })
1065
1187
 
1188
+ it('restarts after a drag with resumeAfter while the pointer and focus stay, with both pauses off', async () => {
1189
+ const user = userEvent.setup()
1190
+ const autoplay = mockAutoplay({ defaultInteraction: false })
1191
+ const { container } = render(<Basic autoplay={{ resumeAfter: 1000, pauseOnHover: false, pauseOnFocus: false }} />)
1192
+ fireEvent.pointerEnter(root(container))
1193
+ await user.tab()
1194
+ expect(autoplay.isPlaying()).toBe(true)
1195
+ vi.useFakeTimers({ toFake: ['setTimeout', 'clearTimeout'] })
1196
+ try {
1197
+ emit('pointerdown')
1198
+ emit('autoplay:interaction', { detail: { interaction: 'pointerdown' } })
1199
+ expect(autoplay.isPlaying()).toBe(false)
1200
+ act(() => vi.advanceTimersByTime(1000))
1201
+ expect(autoplay.isPlaying()).toBe(true)
1202
+ } finally {
1203
+ vi.useRealTimers()
1204
+ }
1205
+ })
1206
+
1066
1207
  it('restarts after resumeAfter once nothing is inside', () => {
1067
1208
  vi.useFakeTimers({ toFake: ['setTimeout', 'clearTimeout'] })
1068
1209
  try {
1069
- const autoplay = mockAutoplay()
1210
+ const autoplay = mockAutoplay({ defaultInteraction: false })
1070
1211
  render(<Basic autoplay={{ resumeAfter: 1000 }} />)
1071
1212
  emit('autoplay:interaction', { detail: { interaction: 'pointerdown' } })
1072
1213
  expect(autoplay.isPlaying()).toBe(false)
@@ -1080,6 +1221,250 @@ describe('Carousel autoplay', () => {
1080
1221
  })
1081
1222
  })
1082
1223
 
1224
+ describe('CarouselPlayToggle', () => {
1225
+ function WithToggle({ children, ...props }: Partial<CarouselProps>) {
1226
+ return (
1227
+ <Carousel {...props}>
1228
+ <CarouselPlayToggle>
1229
+ <svg data-icon="pause" aria-hidden="true" className="in-data-paused:hidden" />
1230
+ <svg data-icon="play" aria-hidden="true" className="not-in-data-paused:hidden" />
1231
+ </CarouselPlayToggle>
1232
+ <CarouselContent>
1233
+ <CarouselSlide>Slide 1</CarouselSlide>
1234
+ <CarouselSlide>Slide 2</CarouselSlide>
1235
+ <CarouselSlide>Slide 3</CarouselSlide>
1236
+ </CarouselContent>
1237
+ <CarouselPrev />
1238
+ <CarouselNext />
1239
+ <CarouselPagination />
1240
+ {children}
1241
+ </Carousel>
1242
+ )
1243
+ }
1244
+
1245
+ function CycleProbe() {
1246
+ const { autoplay } = useCarousel()
1247
+ return <output data-testid="cycle">{autoplay?.cycleId}</output>
1248
+ }
1249
+
1250
+ function root(container: HTMLElement) {
1251
+ return container.querySelector('[data-slot="carousel"]') as HTMLElement
1252
+ }
1253
+
1254
+ const toggle = () => screen.getByRole('button', { name: 'Pause slides' })
1255
+
1256
+ it('renders nothing without Autoplay or Auto Scroll', () => {
1257
+ render(<WithToggle />)
1258
+ expect(screen.queryByRole('button', { name: 'Pause slides' })).toBeNull()
1259
+ })
1260
+
1261
+ it('renders nothing under reduced motion', () => {
1262
+ mockAutoplay()
1263
+ render(
1264
+ <ReducedMotionProvider disableAnimations>
1265
+ <WithToggle autoplay />
1266
+ </ReducedMotionProvider>,
1267
+ )
1268
+ expect(screen.queryByRole('button', { name: 'Pause slides' })).toBeNull()
1269
+ })
1270
+
1271
+ it('renders both icons as children and marks the pause with aria-pressed and data-paused', async () => {
1272
+ const user = userEvent.setup()
1273
+ const autoplay = mockAutoplay()
1274
+ render(<WithToggle autoplay />)
1275
+ const button = toggle()
1276
+ expect(button).toHaveAttribute('data-slot', 'carousel-play-toggle')
1277
+ expect(button).toHaveAttribute('aria-pressed', 'false')
1278
+ expect(button).not.toHaveAttribute('data-paused')
1279
+ expect(button.querySelector('[data-icon="pause"]')).not.toBeNull()
1280
+ expect(button.querySelector('[data-icon="play"]')).not.toBeNull()
1281
+
1282
+ await user.click(button)
1283
+ expect(toggle()).toHaveAttribute('aria-pressed', 'true')
1284
+ expect(toggle()).toHaveAttribute('data-paused')
1285
+ expect(autoplay.isPlaying()).toBe(false)
1286
+
1287
+ await user.click(toggle())
1288
+ expect(toggle()).toHaveAttribute('aria-pressed', 'false')
1289
+ expect(toggle()).not.toHaveAttribute('data-paused')
1290
+ expect(autoplay.isPlaying()).toBe(true)
1291
+ })
1292
+
1293
+ it('passes paused to a render function', async () => {
1294
+ const user = userEvent.setup()
1295
+ mockAutoplay()
1296
+ render(
1297
+ <Carousel autoplay>
1298
+ <CarouselPlayToggle render={(props, state) => <button {...props}>{state.paused ? 'Play' : 'Pause'}</button>} />
1299
+ <CarouselContent>
1300
+ <CarouselSlide>Slide 1</CarouselSlide>
1301
+ <CarouselSlide>Slide 2</CarouselSlide>
1302
+ </CarouselContent>
1303
+ </Carousel>,
1304
+ )
1305
+ expect(toggle()).toHaveTextContent('Pause')
1306
+ await user.click(toggle())
1307
+ expect(toggle()).toHaveTextContent('Play')
1308
+ })
1309
+
1310
+ it('keeps a pause through hover and focus leaving, resumeAfter, a drag, slide focus and the wheel', async () => {
1311
+ const user = userEvent.setup()
1312
+ const viewport = document.createElement('div')
1313
+ const autoplay = mockAutoplay({ defaultInteraction: false })
1314
+ stubApi.plugins.mockReturnValue({ autoplay, wheelGestures: {} })
1315
+ stubApi.rootNode.mockReturnValue(viewport)
1316
+ render(
1317
+ <>
1318
+ <WithToggle autoplay={{ resumeAfter: 1000 }} />
1319
+ <button type="button">Outside</button>
1320
+ </>,
1321
+ )
1322
+ await user.click(toggle())
1323
+ await user.tab()
1324
+ expect(screen.getByRole('button', { name: 'Previous slide' })).toHaveFocus()
1325
+ await user.unhover(toggle())
1326
+ act(() => screen.getByRole('button', { name: 'Outside' }).focus())
1327
+ expect(autoplay.isPlaying()).toBe(false)
1328
+
1329
+ vi.useFakeTimers({ toFake: ['setTimeout', 'clearTimeout'] })
1330
+ try {
1331
+ emit('pointerdown')
1332
+ emit('autoplay:interaction', { detail: { interaction: 'pointerdown' } })
1333
+ emit('slidefocus')
1334
+ emit('autoplay:interaction', { detail: { interaction: 'slidefocus' } })
1335
+ act(() => {
1336
+ viewport.dispatchEvent(new WheelEvent('wheel', { deltaX: 40, deltaY: 2 }))
1337
+ })
1338
+ act(() => vi.advanceTimersByTime(1000))
1339
+ expect(autoplay.isPlaying()).toBe(false)
1340
+ expect(toggle()).toHaveAttribute('aria-pressed', 'true')
1341
+ } finally {
1342
+ vi.useRealTimers()
1343
+ }
1344
+ })
1345
+
1346
+ it('stays paused when paused during a hold, once the hold ends', () => {
1347
+ const autoplay = mockAutoplay()
1348
+ const { container } = render(<WithToggle autoplay />)
1349
+ fireEvent.pointerEnter(root(container))
1350
+ expect(autoplay.isPlaying()).toBe(false)
1351
+ fireEvent.click(toggle())
1352
+ fireEvent.pointerLeave(root(container))
1353
+ expect(autoplay.isPlaying()).toBe(false)
1354
+ expect(toggle()).toHaveAttribute('aria-pressed', 'true')
1355
+ })
1356
+
1357
+ it('keeps the pause when new options restart the plugin wiring', () => {
1358
+ const autoplay = mockAutoplay()
1359
+ const { rerender } = render(<WithToggle autoplay />)
1360
+ fireEvent.click(toggle())
1361
+ rerender(<WithToggle autoplay={{ resumeAfter: 500, pauseOnHover: false }} />)
1362
+ expect(autoplay.isPlaying()).toBe(false)
1363
+ expect(toggle()).toHaveAttribute('aria-pressed', 'true')
1364
+ })
1365
+
1366
+ it('starts a fresh cycle on play, even while hovered', () => {
1367
+ const autoplay = mockAutoplay()
1368
+ const { container } = render(
1369
+ <WithToggle autoplay>
1370
+ <CycleProbe />
1371
+ </WithToggle>,
1372
+ )
1373
+ fireEvent.click(toggle())
1374
+ fireEvent.pointerEnter(root(container))
1375
+ const cycle = Number(screen.getByTestId('cycle').textContent)
1376
+ autoplay.play.mockClear()
1377
+ fireEvent.click(toggle())
1378
+ expect(autoplay.play).toHaveBeenCalledTimes(1)
1379
+ expect(Number(screen.getByTestId('cycle').textContent)).toBe(cycle + 1)
1380
+ expect(autoplay.isPlaying()).toBe(true)
1381
+ })
1382
+
1383
+ it('toggles with Enter and Space', async () => {
1384
+ const user = userEvent.setup()
1385
+ const autoplay = mockAutoplay()
1386
+ render(<WithToggle autoplay />)
1387
+ await user.tab()
1388
+ expect(toggle()).toHaveFocus()
1389
+ await user.keyboard('{Enter}')
1390
+ expect(toggle()).toHaveAttribute('aria-pressed', 'true')
1391
+ expect(autoplay.isPlaying()).toBe(false)
1392
+ await user.keyboard(' ')
1393
+ expect(toggle()).toHaveAttribute('aria-pressed', 'false')
1394
+ expect(autoplay.isPlaying()).toBe(true)
1395
+ })
1396
+
1397
+ it('reads a drag that stops autoplay for good as a pause', () => {
1398
+ mockAutoplay()
1399
+ render(<WithToggle autoplay />)
1400
+ emit('pointerdown')
1401
+ expect(toggle()).toHaveAttribute('aria-pressed', 'true')
1402
+ })
1403
+
1404
+ it('stays unpressed after a drag when autoplay keeps running through it', () => {
1405
+ mockAutoplay({ defaultInteraction: false })
1406
+ render(<WithToggle autoplay={{ defaultInteraction: false }} />)
1407
+ emit('pointerdown')
1408
+ expect(toggle()).toHaveAttribute('aria-pressed', 'false')
1409
+ })
1410
+
1411
+ it('clears the pause when the plugin is played directly', () => {
1412
+ const autoplay = mockAutoplay()
1413
+ render(<WithToggle autoplay />)
1414
+ fireEvent.click(toggle())
1415
+ act(() => autoplay.play())
1416
+ expect(toggle()).toHaveAttribute('aria-pressed', 'false')
1417
+ })
1418
+
1419
+ it('drives Auto Scroll, and resumeAfter leaves its pause alone', () => {
1420
+ const autoScroll = mockAutoScroll()
1421
+ render(<WithToggle autoScroll={{ resumeAfter: 1000 }} />)
1422
+ expect(autoScroll.isPlaying()).toBe(true)
1423
+ fireEvent.click(toggle())
1424
+ expect(autoScroll.isPlaying()).toBe(false)
1425
+ expect(toggle()).toHaveAttribute('aria-pressed', 'true')
1426
+
1427
+ vi.useFakeTimers({ toFake: ['setTimeout', 'clearTimeout'] })
1428
+ try {
1429
+ emit('autoscroll:interaction', { detail: { interaction: 'pointerdown' } })
1430
+ act(() => vi.advanceTimersByTime(1000))
1431
+ expect(autoScroll.isPlaying()).toBe(false)
1432
+ } finally {
1433
+ vi.useRealTimers()
1434
+ }
1435
+
1436
+ fireEvent.click(toggle())
1437
+ expect(autoScroll.isPlaying()).toBe(true)
1438
+ expect(toggle()).toHaveAttribute('aria-pressed', 'false')
1439
+ })
1440
+
1441
+ it('gives a custom control the same paused, pause and play through useCarousel()', async () => {
1442
+ const user = userEvent.setup()
1443
+ const autoplay = mockAutoplay()
1444
+ function Custom() {
1445
+ const { paused, pause, play } = useCarousel()
1446
+ return (
1447
+ <button type="button" onClick={paused ? play : pause}>
1448
+ {paused ? 'Resume' : 'Hold'}
1449
+ </button>
1450
+ )
1451
+ }
1452
+ render(
1453
+ <Carousel autoplay={{ pauseOnHover: false }}>
1454
+ <Custom />
1455
+ <CarouselContent>
1456
+ <CarouselSlide>Slide 1</CarouselSlide>
1457
+ <CarouselSlide>Slide 2</CarouselSlide>
1458
+ </CarouselContent>
1459
+ </Carousel>,
1460
+ )
1461
+ await user.click(screen.getByRole('button', { name: 'Hold' }))
1462
+ expect(autoplay.isPlaying()).toBe(false)
1463
+ await user.click(screen.getByRole('button', { name: 'Resume' }))
1464
+ expect(autoplay.isPlaying()).toBe(true)
1465
+ })
1466
+ })
1467
+
1083
1468
  describe('useLinkedCarousels', () => {
1084
1469
  function makeApi() {
1085
1470
  const stub = {
@@ -1164,6 +1549,26 @@ describe('a11y', () => {
1164
1549
  expect(results).toHaveNoViolations()
1165
1550
  })
1166
1551
 
1552
+ it('has no accessibility violations with a play toggle, playing or paused', async () => {
1553
+ mockAutoplay()
1554
+ const { container } = render(
1555
+ <Carousel autoplay aria-label="Featured">
1556
+ <CarouselPlayToggle>
1557
+ <svg aria-hidden="true" />
1558
+ </CarouselPlayToggle>
1559
+ <CarouselContent>
1560
+ <CarouselSlide>Slide 1</CarouselSlide>
1561
+ <CarouselSlide>Slide 2</CarouselSlide>
1562
+ </CarouselContent>
1563
+ <CarouselPrev />
1564
+ <CarouselNext />
1565
+ </Carousel>,
1566
+ )
1567
+ expect(await axe(container)).toHaveNoViolations()
1568
+ fireEvent.click(screen.getByRole('button', { name: 'Pause slides' }))
1569
+ expect(await axe(container)).toHaveNoViolations()
1570
+ })
1571
+
1167
1572
  it('has no accessibility violations with a thumbnail rail', async () => {
1168
1573
  const { container } = render(
1169
1574
  <Carousel>