-
Notifications
You must be signed in to change notification settings - Fork 159
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(carousel): delay instantiation of IntersectionObserver (#10971)
### Related Ticket(s) Closes #10929 [ADCMS-3414](https://jsw.ibm.com/browse/ADCMS-3414) ### Description Delays the instantiation of the `IntersectionObserver` in the `<dds-carousel>` component until the root element is available, following the patter for how the resize observer gets setup. This should avoid potential race conditions and more reliably get the carousel setup with the correct `inert` attributes on the carousel items. The intent with the `IntersectionObserver` in question here, was always to measure intersection with the carousel's viewport. Unforunately, the way the `IntersectionObserver` has been setup as a class field initializer, it happens too early and the referenced `this._contentsNode` was not yet set, that only happens in the [`update()` lifecycle stage](https://codepen.io/m4olivei/pen/JjwLMZx). Further the element referenced by `this._contentsNode` is a flexbox node, set to nowrap that contains all the carousel items, which overflows the container far off to the right of the screen. It's unclear what the bounding box of that element is, but I was seeing issues with using that element as the root node for the `IntersectionObserver`, so I switched to the parent element instead, which has a defined width and is set to `overflow: hidden`. This gives us a good element to use for the carousel viewport as the `IntersectionObserver` root. ### Changelog **Changed** - delay instantiation of the `IntersectionObserver` in the `<dds-carousel>` component. - changed the root element of the `IntersectionObserver` to `.dds--carousel__scroll-container` - clean up `IntersectionObserver` on ` disconnectedCallback` ### Testing instructions - [ ] Load the "Carousel > Default" story in Canary. In Dev tools, run `document.querySelector('dds-carousel')._intersectionObserver.root`. Note that it's `null`. Run the same in this PR's Storybook instance. It should now be populated with `div.dds--carousel__scroll-container` - [ ] There should be no regressions with the Carousel behavior - [ ] With dev tools open and the `<dds-carousel>` element expanded to show the `<dds-card>` child nodes, verify the correct combinaton of `aria-hidden` and `inert` attributes. Items that are showing to the user should have `aria-hidden="false"` and should not have an `inert` attribute. Items that are hidden to the user should have `aria-hidden="true"` and should have an `inert` attribute. This should hold true as you page through the carousel. NOTE: I've added an e2e test to cover this.
- Loading branch information
Showing
2 changed files
with
115 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters