Skip to content
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

fix(atomic): made facet values focus when pressing show more/show less #2043

Merged
merged 7 commits into from
Jun 6, 2022
Original file line number Diff line number Diff line change
Expand Up @@ -192,10 +192,7 @@ export class AtomicCategoryFacet
@MapProp() @Prop() public dependsOn: Record<string, string> = {};

@FocusTarget()
private showMoreFocus!: FocusTargetController;

@FocusTarget()
private showLessFocus!: FocusTargetController;
private showMoreLessFocus!: FocusTargetController;

@FocusTarget()
private headerFocus!: FocusTargetController;
Expand Down Expand Up @@ -422,7 +419,10 @@ export class AtomicCategoryFacet
);
}

private renderValue(facetValue: CategoryFacetValue) {
private renderValue(
facetValue: CategoryFacetValue,
isShowMoreLessFocusTarget: boolean
) {
const displayValue = getFieldValueCaption(
this.field,
facetValue.value,
Expand All @@ -440,6 +440,9 @@ export class AtomicCategoryFacet
this.facet.toggleSelect(facetValue);
}}
searchQuery={this.facetState.facetSearch.query}
buttonRef={(element) =>
isShowMoreLessFocusTarget && this.showMoreLessFocus.setTarget(element)
}
>
<FacetValueLabelHighlight
displayValue={displayValue}
Expand All @@ -456,7 +459,9 @@ export class AtomicCategoryFacet

return (
<ul part="values" class={this.hasParents ? 'pl-9' : 'mt-3'}>
{this.facetState.values.map((value) => this.renderValue(value))}
{this.facetState.values.map((value, i) =>
this.renderValue(value, i === 0)
)}
</ul>
);
}
Expand Down Expand Up @@ -492,26 +497,21 @@ export class AtomicCategoryFacet
}

private renderShowMoreLess() {
if (this.facetState.canShowMoreValues) {
this.showLessFocus.disableForCurrentSearch();
}
return (
<div class={this.hasParents ? 'pl-9' : ''}>
<FacetShowMoreLess
label={this.label}
i18n={this.bindings.i18n}
onShowMore={() => {
this.showLessFocus.focusAfterSearch();
this.showMoreLessFocus.focusAfterSearch();
this.facet.showMoreValues();
}}
onShowLess={() => {
this.showMoreFocus.focusAfterSearch();
this.showMoreLessFocus.focusAfterSearch();
this.facet.showLessValues();
}}
canShowLessValues={this.facetState.canShowLessValues}
canShowMoreValues={this.facetState.canShowMoreValues}
showMoreRef={this.showMoreFocus.setTarget}
showLessRef={this.showLessFocus.setTarget}
></FacetShowMoreLess>
</div>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,10 +178,7 @@ export class AtomicColorFacet
@MapProp() @Prop() public dependsOn: Record<string, string> = {};

@FocusTarget()
private showMoreFocus!: FocusTargetController;

@FocusTarget()
private showLessFocus!: FocusTargetController;
private showMoreLessFocus!: FocusTargetController;

@FocusTarget()
private headerFocus!: FocusTargetController;
Expand Down Expand Up @@ -295,7 +292,11 @@ export class AtomicColorFacet
);
}

private renderValue(facetValue: FacetValue, onClick: () => void) {
private renderValue(
facetValue: FacetValue,
onClick: () => void,
isShowMoreLessFocusTarget: boolean
) {
const displayValue = getFieldValueCaption(
this.facetId!,
facetValue.value,
Expand All @@ -314,6 +315,10 @@ export class AtomicColorFacet
i18n={this.bindings.i18n}
onClick={onClick}
searchQuery={this.facetState.facetSearch.query}
buttonRef={(element) =>
isShowMoreLessFocusTarget &&
this.showMoreLessFocus.setTarget(element)
}
>
<FacetValueLabelHighlight
displayValue={displayValue}
Expand All @@ -331,6 +336,10 @@ export class AtomicColorFacet
i18n={this.bindings.i18n}
onClick={onClick}
searchQuery={this.facetState.facetSearch.query}
buttonRef={(element) =>
isShowMoreLessFocusTarget &&
this.showMoreLessFocus.setTarget(element)
}
>
<div
part={`value-${partValueWithDisplayValue} value-${partValueWithAPIValue} default-color-value`}
Expand Down Expand Up @@ -365,22 +374,23 @@ export class AtomicColorFacet

private renderValues() {
return this.renderValuesContainer(
this.facetState.values.map((value) =>
this.renderValue(value, () => this.facet.toggleSelect(value))
this.facetState.values.map((value, i) =>
this.renderValue(value, () => this.facet.toggleSelect(value), i === 0)
)
);
}

private renderSearchResults() {
return this.renderValuesContainer(
this.facetState.facetSearch.values.map((value) =>
this.facetState.facetSearch.values.map((value, i) =>
this.renderValue(
{
state: 'idle',
numberOfResults: value.count,
value: value.rawValue,
},
() => this.facet.facetSearch.select(value)
() => this.facet.facetSearch.select(value),
i === 0
)
),
this.facetState.facetSearch.query
Expand All @@ -399,25 +409,20 @@ export class AtomicColorFacet
}

private renderShowMoreLess() {
if (this.facetState.canShowMoreValues) {
this.showLessFocus.disableForCurrentSearch();
}
return (
<FacetShowMoreLess
label={this.label}
i18n={this.bindings.i18n}
onShowMore={() => {
this.showLessFocus.focusAfterSearch();
this.showMoreLessFocus.focusAfterSearch();
this.facet.showMoreValues();
}}
onShowLess={() => {
this.showMoreFocus.focusAfterSearch();
this.showMoreLessFocus.focusAfterSearch();
this.facet.showLessValues();
}}
canShowLessValues={this.facetState.canShowLessValues}
canShowMoreValues={this.facetState.canShowMoreValues}
showMoreRef={this.showMoreFocus.setTarget}
showLessRef={this.showLessFocus.setTarget}
></FacetShowMoreLess>
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,10 +179,7 @@ export class AtomicFacet implements InitializableComponent, BaseFacet<Facet> {
@MapProp() @Prop() public dependsOn: Record<string, string> = {};

@FocusTarget()
private showMoreFocus!: FocusTargetController;

@FocusTarget()
private showLessFocus!: FocusTargetController;
private showMoreLessFocus!: FocusTargetController;

@FocusTarget()
private headerFocus!: FocusTargetController;
Expand Down Expand Up @@ -303,7 +300,11 @@ export class AtomicFacet implements InitializableComponent, BaseFacet<Facet> {
);
}

private renderValue(facetValue: FacetValue, onClick: () => void) {
private renderValue(
facetValue: FacetValue,
onClick: () => void,
isShowMoreLessFocusTarget: boolean
) {
const displayValue = getFieldValueCaption(
this.field,
facetValue.value,
Expand All @@ -320,6 +321,10 @@ export class AtomicFacet implements InitializableComponent, BaseFacet<Facet> {
i18n={this.bindings.i18n}
onClick={onClick}
searchQuery={this.facetState.facetSearch.query}
buttonRef={(element) =>
isShowMoreLessFocusTarget &&
this.showMoreLessFocus.setTarget(element)
}
>
<FacetValueLabelHighlight
displayValue={displayValue}
Expand All @@ -337,6 +342,10 @@ export class AtomicFacet implements InitializableComponent, BaseFacet<Facet> {
i18n={this.bindings.i18n}
onClick={onClick}
searchQuery={this.facetState.facetSearch.query}
buttonRef={(element) =>
isShowMoreLessFocusTarget &&
this.showMoreLessFocus.setTarget(element)
}
>
<FacetValueLabelHighlight
displayValue={displayValue}
Expand All @@ -354,6 +363,10 @@ export class AtomicFacet implements InitializableComponent, BaseFacet<Facet> {
i18n={this.bindings.i18n}
onClick={onClick}
searchQuery={this.facetState.facetSearch.query}
buttonRef={(element) =>
isShowMoreLessFocusTarget &&
this.showMoreLessFocus.setTarget(element)
}
>
<FacetValueLabelHighlight
displayValue={displayValue}
Expand Down Expand Up @@ -384,11 +397,14 @@ export class AtomicFacet implements InitializableComponent, BaseFacet<Facet> {

private renderValues() {
return this.renderValuesContainer(
this.facetState.values.map((value) =>
this.renderValue(value, () =>
this.displayValuesAs === 'link'
? this.facet.toggleSingleSelect(value)
: this.facet.toggleSelect(value)
this.facetState.values.map((value, i) =>
this.renderValue(
value,
() =>
this.displayValuesAs === 'link'
? this.facet.toggleSingleSelect(value)
: this.facet.toggleSelect(value),
i === 0
)
)
);
Expand All @@ -406,7 +422,8 @@ export class AtomicFacet implements InitializableComponent, BaseFacet<Facet> {
() =>
this.displayValuesAs === 'link'
? this.facet.facetSearch.singleSelect(value)
: this.facet.facetSearch.select(value)
: this.facet.facetSearch.select(value),
false
)
),
this.facetState.facetSearch.query
Expand All @@ -425,25 +442,20 @@ export class AtomicFacet implements InitializableComponent, BaseFacet<Facet> {
}

private renderShowMoreLess() {
if (this.facetState.canShowMoreValues) {
this.showLessFocus.disableForCurrentSearch();
}
return (
<FacetShowMoreLess
label={this.label}
i18n={this.bindings.i18n}
onShowMore={() => {
this.showLessFocus.focusAfterSearch();
this.showMoreLessFocus.focusAfterSearch();
this.facet.showMoreValues();
}}
onShowLess={() => {
this.showMoreFocus.focusAfterSearch();
this.showMoreLessFocus.focusAfterSearch();
this.facet.showLessValues();
}}
canShowMoreValues={this.facetState.canShowMoreValues}
canShowLessValues={this.facetState.canShowLessValues}
showMoreRef={this.showMoreFocus.setTarget}
showLessRef={this.showLessFocus.setTarget}
></FacetShowMoreLess>
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export const FacetValueBox: FunctionalComponent<FacetValueProps> = (
}`}
ariaPressed={props.isSelected.toString()}
ariaLabel={ariaLabel}
ref={props.buttonRef}
>
{children}
<span
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ export const FacetValueCheckbox: FunctionalComponent<FacetValueProps> = (
: 'border border-neutral-dark'
}`}
aria-label={ariaLabel}
ref={props.buttonRef}
>
<atomic-icon
class={`w-3/5 svg-checkbox ${props.isSelected ? 'block' : 'hidden'}`}
Expand Down