diff --git a/CHANGELOG.md b/CHANGELOG.md index 4bbe3b9..91c3f0f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. ### Changed - Update GitHub actions/cache to v4 +- Web Accessibility: Change quantity div to label element and add htmlFor that links to quantity input ## [1.9.0] - 2022-12-23 diff --git a/react/components/BaseProductQuantity.tsx b/react/components/BaseProductQuantity.tsx index 3cb1cd9..513a1f1 100644 --- a/react/components/BaseProductQuantity.tsx +++ b/react/components/BaseProductQuantity.tsx @@ -1,6 +1,7 @@ import React, { useCallback } from 'react' import { FormattedMessage } from 'react-intl' import { useCssHandles } from 'vtex.css-handles' +import { useRuntime } from 'vtex.render-runtime' import { DispatchFunction } from 'vtex.product-context/ProductDispatchContext' import { ProductContext } from 'vtex.product-context' @@ -44,7 +45,11 @@ const BaseProductQuantity: StorefrontFunctionComponent = ({ showUnit = true, quantitySelectorStep = 'unitMultiplier', }) => { + const { getSettings } = useRuntime() + const settings = getSettings('vtex.store') + const useSemanticHtml = settings?.advancedSettings?.a11ySemanticHtmlMigration const handles = useCssHandles(CSS_HANDLES) + const onChange = useCallback( (e: OnChangeCallback) => { dispatch({ type: 'SET_QUANTITY', args: { quantity: e.value } }) @@ -64,14 +69,22 @@ const BaseProductQuantity: StorefrontFunctionComponent = ({ const unitMultiplier = quantitySelectorStep === 'singleUnit' ? 1 : selectedItem.unitMultiplier + const LabelComponent = useSemanticHtml ? 'label' : 'div' + const labelProps = useSemanticHtml + ? { + htmlFor: 'vtex-product-quantity-input', + } + : {} + return (
{showLabel && ( -
+ -
+ )} {selectorType === 'stepper' && ( = ({ selectedQuantity={selectedQuantity} availableQuantity={availableQuantity} onChange={onChange} + useSemanticHtml={useSemanticHtml} /> )} {selectorType === 'dropdown' && ( diff --git a/react/components/StepperProductQuantity.tsx b/react/components/StepperProductQuantity.tsx index dc2f07a..18b056d 100644 --- a/react/components/StepperProductQuantity.tsx +++ b/react/components/StepperProductQuantity.tsx @@ -15,6 +15,7 @@ interface StepperProps { onChange: (e: OnChangeCallback) => void size: BaseProps['size'] showUnit: boolean + useSemanticHtml?: boolean } const CSS_HANDLES = ['quantitySelectorStepper'] as const @@ -27,6 +28,7 @@ const StepperProductQuantity: FunctionComponent = ({ availableQuantity, onChange, showUnit, + useSemanticHtml = false, }) => { const handles = useCssHandles(CSS_HANDLES) @@ -44,6 +46,7 @@ const StepperProductQuantity: FunctionComponent = ({ onChange={onChange} value={selectedQuantity} maxValue={availableQuantity || undefined} + useSemanticHtml={useSemanticHtml} />
) diff --git a/react/typings/vtex.styleguide.d.ts b/react/typings/vtex.styleguide.d.ts index 3f0a9de..14e3734 100644 --- a/react/typings/vtex.styleguide.d.ts +++ b/react/typings/vtex.styleguide.d.ts @@ -15,6 +15,7 @@ declare module 'vtex.styleguide' { unitMultiplier: number suffix?: string onChange: (e: any) => void + useSemanticHtml?: any } interface DropdownProps {