Skip to content
Merged
Show file tree
Hide file tree
Changes from 7 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
21 changes: 18 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 @@
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,23 @@
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}

Check failure on line 85 in react/components/BaseProductQuantity.tsx

View workflow job for this annotation

GitHub Actions / Lint

Delete `⏎········`
>

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's still a lint error here that needs to be fixed.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vsseixaso Format for linting issues is a bit unclear. Does this mean to put {...labelProps} on line 84?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, think it's asking for the closing '>' tag to be put on the previous line. Have added it in a new commit, Please retry linting and let me know.

<FormattedMessage id="store/product-quantity.quantity" />
</div>
</LabelComponent>
)}
{selectorType === 'stepper' && (
<StepperProductQuantity
Expand All @@ -82,6 +96,7 @@
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 @@ -14,13 +14,14 @@
maxValue?: number
unitMultiplier: number
suffix?: string
onChange: (e: any) => void

Check warning on line 17 in react/typings/vtex.styleguide.d.ts

View workflow job for this annotation

GitHub Actions / Lint

Unexpected any. Specify a different type
useSemanticHtml?: any

Check warning on line 18 in react/typings/vtex.styleguide.d.ts

View workflow job for this annotation

GitHub Actions / Lint

Unexpected any. Specify a different type
}

interface DropdownProps {
id: string
testId: string
onChange: (e: any) => void

Check warning on line 24 in react/typings/vtex.styleguide.d.ts

View workflow job for this annotation

GitHub Actions / Lint

Unexpected any. Specify a different type
placeholder: string
options: Array<{
value: number
Expand All @@ -35,7 +36,7 @@
size: NumericSize
value: string
maxLength: number
onChange: (e: any) => void

Check warning on line 39 in react/typings/vtex.styleguide.d.ts

View workflow job for this annotation

GitHub Actions / Lint

Unexpected any. Specify a different type
onBlur: () => void
placeholder: string
}
Expand Down
Loading