Skip to content

[A11Y] - Fix action btn #1402

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 5 commits into from
Apr 24, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions packages/gallery/src/components/item/itemHelper.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,35 +39,35 @@ function isThisGalleryElementInFocus(className, galleryId) {
export function changeActiveElementIfNeeded({
prevProps,
currentProps,
itemContainer,
itemActionRef,
}) {
try {
if (
shouldChangeActiveElement() &&
window.document.activeElement.className
) {
const isGalleryItemInFocus = isThisGalleryElementInFocus(
'gallery-item-container',
const isGalleryItemAction = isThisGalleryElementInFocus(
'item-action',
currentProps.galleryId
);
const isShowMoreInFocus = isThisGalleryElementInFocus(
'show-more',
currentProps.galleryId
);
if (isGalleryItemInFocus || isShowMoreInFocus) {
if (isGalleryItemAction || isShowMoreInFocus) {
if (
currentProps.thumbnailHighlightId !==
prevProps.thumbnailHighlightId &&
currentProps.thumbnailHighlightId === currentProps.id
) {
// if the highlighted thumbnail changed and it is the same as this itemview's
itemContainer.focus();
itemActionRef.focus();
} else if (
currentProps.activeIndex !== prevProps.activeIndex &&
currentProps.activeIndex === currentProps.idx
) {
//check if activeIndex has changed to the current item
itemContainer.focus();
itemActionRef.focus();
}
}
}
Expand Down
1 change: 0 additions & 1 deletion packages/gallery/src/components/item/itemHover.js
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,6 @@ export default class ItemHover extends React.Component {
<div
key={'item-hover-' + idx}
data-hook={'item-hover-' + idx}
aria-hidden={true}
className={hoverClass}
onTouchStart={actions.handleItemMouseDown}
onTouchEnd={actions.handleItemMouseUp}
Expand Down
34 changes: 29 additions & 5 deletions packages/gallery/src/components/item/itemView.js
Original file line number Diff line number Diff line change
Expand Up @@ -960,7 +960,7 @@ class ItemView extends React.Component {
changeActiveElementIfNeeded({
prevProps,
currentProps: this.props,
itemContainer: this.itemContainer,
itemActionRef: this.itemActionRef,
});
}

Expand Down Expand Up @@ -1000,6 +1000,16 @@ class ItemView extends React.Component {
}
}

getItemAriaHaspopup() {
switch (this.props.options.itemClick) {
case 'expand':
case 'fullscreen':
return true;
default:
return '';
}
}

composeItem() {
const { photoId, id, hash, idx, options, type, url } = this.props;

Expand All @@ -1010,6 +1020,8 @@ class ItemView extends React.Component {
options.titlePlacement !== GALLERY_CONSTS.placements.SHOW_ON_HOVER &&
!this.hasRequiredMediaUrl;
const itemAriaRole = this.getItemAriaRole();
const itemAriaLabel = this.getItemAriaLabel();
const itemAriaHaspopup = this.getItemAriaHaspopup();
const Element = this.props.elementsOverride?.item || 'div';
const innerDiv = (
<Element
Expand All @@ -1020,19 +1032,31 @@ class ItemView extends React.Component {
onMouseEnter={this.onMouseEnter}
onMouseLeave={this.onMouseLeave}
onFocus={this.onFocus}
onBlur={this.onBlur} // The onblur event is the opposite of the onfocus event.
tabIndex={this.getItemContainerTabIndex()}
aria-label={this.getItemAriaLabel()}
onBlur={this.onBlur}
data-hash={hash}
data-id={photoId}
data-idx={idx}
{...(itemAriaRole && { role: itemAriaRole })}
data-hook="item-container"
key={'item-container-' + id}
style={this.getItemContainerStyles()}
onKeyUp={this.onContainerKeyUp}
onClick={this.onItemWrapperClick}
>
<div
data-idx={idx}
id={'item-action-' + id}
className="item-action"
ref={(ref) => (this.itemActionRef = ref)}
onKeyUp={this.onContainerKeyUp}
tabIndex={this.getItemContainerTabIndex()}
onFocus={this.onFocus}
onBlur={this.onBlur}
data-hook={'item-action'}
{...(itemAriaLabel && { ['aria-label']: itemAriaLabel })}
{...(itemAriaRole && { role: itemAriaRole })}
{...(itemAriaHaspopup && { ['aria-haspopup']: itemAriaHaspopup })}
></div>

{this.getTopInfoElementIfNeeded()}
{this.getLeftInfoElementIfNeeded()}
<div
Expand Down
17 changes: 14 additions & 3 deletions packages/gallery/src/components/styles/gallery.scss
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,19 @@ div.pro-gallery {
font-size: 11px;
cursor: default;
scroll-snap-align: center;

.item-action {
width: 1px;
height: 1px;
overflow: hidden;
position: absolute;
pointer-events: none;
z-index: -1;
&:focus {
--focus-ring-box-shadow: none !important;
outline: none !important;
box-shadow: none !important;
}
}
&:hover {
.gallery-item-common-info {
cursor: pointer;
Expand Down Expand Up @@ -680,8 +692,7 @@ div.pro-gallery {
.thumbnailItem.pro-gallery-highlight::after {
box-shadow: inset 0 0 1px 2px $wix-blue, inset 0 0 7px 0 $white, 0 0 10px -5px $wix-blue;
}

.gallery-item-container:focus::after {
.gallery-item-container:has(.item-action:focus)::after {
content: ' ';
width: 100%;
height: 100%;
Expand Down
8 changes: 4 additions & 4 deletions packages/gallery/tests/styleParams/itemClick.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ describe('options - itemClick', () => {
});
driver.mount.proGallery(initialProps);
await driver.update();
const item = driver.find.hook('item-container').at(3);
const item = driver.find.hook('item-action').at(3);
expect(item.props().role).to.eq('link');
driver.detach.proGallery();
});
Expand All @@ -35,7 +35,7 @@ describe('options - itemClick', () => {
});
driver.mount.proGallery(initialProps);
await driver.update();
const item = driver.find.hook('item-container').at(3);
const item = driver.find.hook('item-action').at(3);
expect(item.props().role).to.eq('button');
driver.detach.proGallery();
});
Expand All @@ -45,7 +45,7 @@ describe('options - itemClick', () => {
});
driver.mount.proGallery(initialProps);
await driver.update();
const item = driver.find.hook('item-container').at(3);
const item = driver.find.hook('item-action').at(3);
expect(item.props().role).to.eq('button');
driver.detach.proGallery();
});
Expand All @@ -55,7 +55,7 @@ describe('options - itemClick', () => {
});
driver.mount.proGallery(initialProps);
await driver.update();
const item = driver.find.hook('item-container').at(3);
const item = driver.find.hook('item-action').at(3);
expect(item.props()).to.not.have.property('role');
driver.detach.proGallery();
});
Expand Down
Loading