Skip to content
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
20 changes: 17 additions & 3 deletions react/components/BaseProductQuantity.tsx
Original file line number Diff line number Diff line change
@@ -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'

Expand Down Expand Up @@ -44,7 +45,11 @@ const BaseProductQuantity: StorefrontFunctionComponent<BaseProps> = ({
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 } })
Expand All @@ -64,14 +69,22 @@ const BaseProductQuantity: StorefrontFunctionComponent<BaseProps> = ({
const unitMultiplier =
quantitySelectorStep === 'singleUnit' ? 1 : selectedItem.unitMultiplier

const LabelComponent = useSemanticHtml ? 'label' : 'div'
const labelProps = useSemanticHtml
? {
htmlFor: 'vtex-product-quantity-input',
}
: {}

return (
<div
className={`${handles.quantitySelectorContainer} flex flex-column mb4`}>
{showLabel && (
<div
className={`${handles.quantitySelectorTitle} mb3 c-muted-2 t-body`}>
<LabelComponent
className={`${handles.quantitySelectorTitle} mb3 c-muted-2 t-body`}
{...labelProps}>
<FormattedMessage id="store/product-quantity.quantity" />
</div>
</LabelComponent>
)}
{selectorType === 'stepper' && (
<StepperProductQuantity
Expand All @@ -82,6 +95,7 @@ const BaseProductQuantity: StorefrontFunctionComponent<BaseProps> = ({
selectedQuantity={selectedQuantity}
availableQuantity={availableQuantity}
onChange={onChange}
useSemanticHtml={useSemanticHtml}
/>
)}
{selectorType === 'dropdown' && (
Expand Down
3 changes: 3 additions & 0 deletions react/components/StepperProductQuantity.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ interface StepperProps {
onChange: (e: OnChangeCallback) => void
size: BaseProps['size']
showUnit: boolean
useSemanticHtml?: boolean
}

const CSS_HANDLES = ['quantitySelectorStepper'] as const
Expand All @@ -27,6 +28,7 @@ const StepperProductQuantity: FunctionComponent<StepperProps> = ({
availableQuantity,
onChange,
showUnit,
useSemanticHtml = false,
}) => {
const handles = useCssHandles(CSS_HANDLES)

Expand All @@ -44,6 +46,7 @@ const StepperProductQuantity: FunctionComponent<StepperProps> = ({
onChange={onChange}
value={selectedQuantity}
maxValue={availableQuantity || undefined}
useSemanticHtml={useSemanticHtml}
/>
</div>
)
Expand Down
1 change: 1 addition & 0 deletions react/typings/vtex.styleguide.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ declare module 'vtex.styleguide' {
unitMultiplier: number
suffix?: string
onChange: (e: any) => void
useSemanticHtml?: any
}

interface DropdownProps {
Expand Down
Loading