-
Notifications
You must be signed in to change notification settings - Fork 126
[ACCESSIBILITY - PART 3] Product page improvements #758
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 5 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
3ae3fe8
fix: modal update duplication
tblivet 80e4a23
fix: zoom button duplicate
tblivet 9a5936c
feat: accessibility improvements
tblivet ef0a1a8
feat: product variants accessibility
tblivet ada51ce
feat: a11y improvements
tblivet 0a417d0
feat: review
tblivet 5a6607e
fix : review
tblivet File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,120 @@ | ||
| /** | ||
| * For the full copyright and license information, please view the LICENSE | ||
| * file that was distributed with this source code. | ||
| */ | ||
|
|
||
| import {Carousel} from 'bootstrap'; | ||
| import SelectorsMap from '../constants/selectors-map'; | ||
|
|
||
| export default () => { | ||
| const {prestashop, Theme: {events}} = window; | ||
|
|
||
| // Product images sync on open/close modal | ||
| document.addEventListener('show.bs.modal', (event) => { | ||
| const modal = event.target as HTMLElement; | ||
|
|
||
| if (!modal.matches(SelectorsMap.product.productImagesModal)) return; | ||
|
|
||
| const modalCarouselElement = modal.querySelector(SelectorsMap.product.productImagesModalCarousel); | ||
| const mainCarouselElement = document.querySelector(SelectorsMap.product.carousel); | ||
|
|
||
| if (!modalCarouselElement || !mainCarouselElement) return; | ||
|
|
||
| const modalCarousel = Carousel.getOrCreateInstance(modalCarouselElement as HTMLElement); | ||
| const activeIndex = getActiveSlideIndex(mainCarouselElement as HTMLElement); | ||
|
|
||
| if (activeIndex !== -1) { | ||
| modalCarousel.to(activeIndex); | ||
| } | ||
| }); | ||
|
|
||
| document.addEventListener('hide.bs.modal', (event) => { | ||
| const modal = event.target as HTMLElement; | ||
|
|
||
| if (!modal.matches(SelectorsMap.product.productImagesModal)) return; | ||
|
|
||
| const modalCarouselElement = modal.querySelector(SelectorsMap.product.productImagesModalCarousel); | ||
| const mainCarouselElement = document.querySelector(SelectorsMap.product.carousel); | ||
|
|
||
| if (!modalCarouselElement || !mainCarouselElement) return; | ||
|
|
||
| const mainCarousel = Carousel.getOrCreateInstance(mainCarouselElement as HTMLElement); | ||
| const activeIndex = getActiveSlideIndex(modalCarouselElement as HTMLElement); | ||
|
|
||
| if (activeIndex !== -1) { | ||
| mainCarousel.to(activeIndex); | ||
| } | ||
| }); | ||
|
|
||
| const getActiveSlideIndex = (carouselEl: HTMLElement): number => { | ||
| const items = carouselEl.querySelectorAll('.carousel-item'); | ||
|
|
||
| return Array.from(items).findIndex((item) => item.classList.contains('active')); | ||
| }; | ||
|
|
||
| // Stores the element to refocus, per context ("main" or "quickview") | ||
| const focusMap = new Map<'quickview' | 'main', { id: string }>(); | ||
|
|
||
| // Save the element before the update | ||
| prestashop.on(events.updateProduct, ({ event }: { event: Event }) => { | ||
|
Check failure on line 59 in src/js/accessibility/product.ts
|
||
| const target = event?.target as HTMLElement; | ||
| if (!target || !target.id) return; | ||
|
|
||
| const isInQuickView = !!target.closest(SelectorsMap.quickviewModal); | ||
| const context: 'quickview' | 'main' = isInQuickView ? 'quickview' : 'main'; | ||
|
|
||
| focusMap.set(context, { id: target.id }); | ||
|
Check failure on line 66 in src/js/accessibility/product.ts
|
||
| }); | ||
|
|
||
| // Restore focus after update | ||
| prestashop.on(events.updatedProduct, () => { | ||
| focusMap.forEach((focusData, context) => { | ||
| let container: HTMLElement | null = null; | ||
|
|
||
| if (context === 'quickview') { | ||
| container = document.querySelector(SelectorsMap.quickviewModal); | ||
| } else { | ||
| container = document.querySelector(SelectorsMap.product.container); | ||
| } | ||
|
|
||
| if (!container) return; | ||
|
|
||
| const elementToFocus = container.querySelector<HTMLElement>(`#${focusData.id}`); | ||
|
|
||
| if (elementToFocus) { | ||
| elementToFocus.focus(); | ||
|
|
||
| // Emit event to when the focus is restored | ||
| prestashop.emit(events.combinationFocusRestored, { | ||
| context, | ||
| elementId: focusData.id | ||
| }); | ||
| } | ||
|
|
||
| focusMap.delete(context); | ||
| }); | ||
| }); | ||
|
|
||
| // Product availability messages announcement | ||
| prestashop.on(events.combinationFocusRestored, ({ context }: { context: 'quickview' | 'main' }) => { | ||
|
Check failure on line 99 in src/js/accessibility/product.ts
|
||
| let container: HTMLElement | null = null; | ||
|
|
||
| // Get the container of the context | ||
| if (context === 'quickview') { | ||
| container = document.querySelector(SelectorsMap.quickviewModal); | ||
| } else { | ||
| container = document.querySelector(SelectorsMap.product.container); | ||
| } | ||
|
|
||
| if (!container) return; | ||
|
|
||
| const productAvailabilityElement = container.querySelector(SelectorsMap.product.productAvailability); | ||
|
|
||
| if (!productAvailabilityElement) return; | ||
|
|
||
| // Delay to ensure focus announcement finishes first | ||
| setTimeout(() => { | ||
| productAvailabilityElement.setAttribute('aria-live', 'polite'); | ||
| }, 250); | ||
| }); | ||
| }; | ||
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.