Skip to content

Commit

Permalink
fix: sfscrollable add props for buttons aria labels (#2848)
Browse files Browse the repository at this point in the history
* fix: add props for buttons aria labels

* chore: add changeset notes
  • Loading branch information
AdamPawlinski committed Jun 23, 2023
1 parent e3c66d5 commit 93107ab
Show file tree
Hide file tree
Showing 7 changed files with 60 additions and 0 deletions.
6 changes: 6 additions & 0 deletions .changeset/sharp-scissors-heal.md
@@ -0,0 +1,6 @@
---
'@storefront-ui/react': minor
'@storefront-ui/vue': minor
---

Added props changing aria label for nav buttons in SfScrollable
2 changes: 2 additions & 0 deletions apps/docs/components/components/scrollable.md
Expand Up @@ -86,6 +86,8 @@ By default `SfScrollable` scroll by one page of items, but can be modified that
| `prevDisabled` | `boolean` | | |
| `nextDisabled` | `boolean` | | |
| `isActiveIndexCentered` | `boolean` | | |
| `buttonPrevAriaLabel` | `string` | `'Previous'` | |
| `buttonNextAriaLabel` | `string` | `'Next'` | |
<!-- vue -->
| `tag` | `string` | `'div'` | |
<!-- end vue -->
Expand Down
18 changes: 18 additions & 0 deletions apps/preview/next/pages/examples/SfScrollable.tsx
Expand Up @@ -35,12 +35,28 @@ function Example() {
propDefaultValue: '10',
description: 'Only for demonstration purposes. Total number of items',
},
{
type: 'text',
modelName: 'buttonPrevAriaLabel',
propType: 'string',
propDefaultValue: 'Previous',
description: 'Sets aria label for the previous button',
},
{
type: 'text',
modelName: 'buttonNextAriaLabel',
propType: 'string',
propDefaultValue: 'Next',
description: 'Sets aria label for the next button',
},
],
{
direction: SfScrollableDirection.horizontal,
buttonsPlacement: SfScrollableButtonsPlacement.block,
drag: undefined,
totalItems: '20',
buttonPrevAriaLabel: 'Previous element',
buttonNextAriaLabel: 'Next element',
},
);

Expand All @@ -50,6 +66,8 @@ function Example() {
drag={state.get.drag}
direction={state.get.direction}
buttonsPlacement={state.get.buttonsPlacement}
buttonPrevAriaLabel={state.get.buttonPrevAriaLabel}
buttonNextAriaLabel={state.get.buttonNextAriaLabel}
className="items-center w-full"
>
{Array.from({ length: Number(state.get.totalItems || 10) }, (_, i) => (
Expand Down
18 changes: 18 additions & 0 deletions apps/preview/nuxt/pages/examples/SfScrollable.vue
Expand Up @@ -4,6 +4,8 @@
:drag="state.drag"
:direction="state.direction"
:buttons-placement="state.buttonsPlacement"
:button-prev-aria-label="state.buttonPrevAriaLabel"
:button-next-aria-label="state.buttonNextAriaLabel"
class="w-full items-center"
>
<div
Expand Down Expand Up @@ -54,12 +56,28 @@ const { controlsAttrs, state } = prepareControls(
propDefaultValue: '10',
description: 'Only for demonstration purposes. Total number of items',
},
{
type: 'text',
modelName: 'buttonPrevAriaLabel',
propType: 'string',
propDefaultValue: 'Previous',
description: 'Sets aria label for the previous button',
},
{
type: 'text',
modelName: 'buttonNextAriaLabel',
propType: 'string',
propDefaultValue: 'Next',
description: 'Sets aria label for the next button',
},
],
{
direction: ref(SfScrollableDirection.horizontal),
buttonsPlacement: ref(SfScrollableButtonsPlacement.block),
drag: ref(),
totalItems: ref('20'),
buttonPrevAriaLabel: ref('Previous element'),
buttonNextAriaLabel: ref('Next element'),
},
);
</script>
Expand Up @@ -34,6 +34,8 @@ const SfScrollable = polymorphicForwardRef<typeof defaultScrollableTag, SfScroll
wrapperClassName,
prevDisabled,
nextDisabled,
buttonPrevAriaLabel = 'Previous',
buttonNextAriaLabel = 'Next',
style,
children,
slotPreviousButton,
Expand Down Expand Up @@ -88,6 +90,7 @@ const SfScrollable = polymorphicForwardRef<typeof defaultScrollableTag, SfScroll
size: 'lg',
disabled: prevDisabled,
slotPrefix: <SfIconChevronLeft />,
ariaLabel: buttonPrevAriaLabel,
className: classNames(
'hidden md:block !ring-neutral-500 !text-neutral-500 disabled:!ring-disabled-300 disabled:!text-disabled-500',
classNameButton,
Expand All @@ -109,6 +112,7 @@ const SfScrollable = polymorphicForwardRef<typeof defaultScrollableTag, SfScroll
size: 'lg',
disabled: nextDisabled,
slotPrefix: <SfIconChevronRight />,
ariaLabel: buttonNextAriaLabel,
className: classNames(
'hidden md:block !ring-neutral-500 !text-neutral-500 disabled:!ring-disabled-300 disabled:!text-disabled-500',
classNameButton,
Expand Down
Expand Up @@ -8,5 +8,7 @@ export interface SfScrollableProps extends UseScrollableOptions, PropsWithChildr
slotNextButton?: ReactElement;
prevDisabled?: boolean;
nextDisabled?: boolean;
buttonPrevAriaLabel?: string;
buttonNextAriaLabel?: string;
buttonsPlacement?: `${SfScrollableButtonsPlacement}`;
}
Expand Up @@ -59,6 +59,14 @@ const props = defineProps({
type: Boolean,
default: false,
},
buttonPrevAriaLabel: {
type: String,
default: 'Previous',
},
buttonNextAriaLabel: {
type: String,
default: 'Next',
},
});
const emit = defineEmits<{
(e: 'onDragStart', data: SfScrollableOnDragStartData): void;
Expand Down Expand Up @@ -112,6 +120,7 @@ const isHorizontal = computed(() => props.direction === SfScrollableDirection.ho
]"
v-bind="getPrevButtonProps"
:disabled="prevDisabled"
:aria-label="buttonPrevAriaLabel"
>
<SfIconChevronLeft />
</SfButton>
Expand Down Expand Up @@ -150,6 +159,7 @@ const isHorizontal = computed(() => props.direction === SfScrollableDirection.ho
]"
v-bind="getNextButtonProps"
:disabled="nextDisabled"
:aria-label="buttonNextAriaLabel"
>
<SfIconChevronRight />
</SfButton>
Expand Down

0 comments on commit 93107ab

Please sign in to comment.