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

feat(components/molecule/stepper): add label to each step a11y #2757

Merged
merged 2 commits into from
Sep 9, 2024
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
11 changes: 11 additions & 0 deletions components/molecule/stepper/demo/articles/ArticlePlayground.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ const ArticlePlayground = ({className}) => {
const [icon, setIcon] = useState(false)
const [visitedIcon, setVisitedIcon] = useState(false)
const [currentIcon, setCurrentIcon] = useState(false)
const [showLabel, setShowLabel] = useState(true)
const updateSteps = steps => {
setSteps(steps)
steps - 1 < step && setStep(steps - 1)
Expand Down Expand Up @@ -108,6 +109,7 @@ const ArticlePlayground = ({className}) => {
onChange={(event, {step}) => setStep(step)}
visitedIcon={visitedIcon && iconVisited}
currentIcon={currentIcon && iconCurrent}
showLabel={showLabel}
icon={icon && iconDefault}
labels={Array(steps)
.fill()
Expand All @@ -132,6 +134,7 @@ const ArticlePlayground = ({className}) => {
visited={index + 1 < step}
current={step === index + 1}
onClick={(event, {step}) => setStep(step)}
showLabel={showLabel}
>
<CustomStep />
</Step>
Expand Down Expand Up @@ -186,6 +189,14 @@ const ArticlePlayground = ({className}) => {
fullWidth
/>
</Cell>
<Cell span={2}>
<Label>Show Label</Label>
</Cell>
<Cell span={2} />
<Cell span={2} />
<Cell span={2}>
<RadioButton label="showLabel" checked={showLabel} onClick={() => setShowLabel(!showLabel)} fullWidth />
</Cell>
</Grid>
</Article>
)
Expand Down
12 changes: 7 additions & 5 deletions components/molecule/stepper/src/Step/DefaultStep.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import PropTypes from 'prop-types'

import {naturalNumber} from '../prop-types.js'
import {ALIGNMENT, DESIGN} from '../settings.js'
import {BASE_CLASS_STEP, getIcon, getLabel} from './settings.js'
import {BASE_CLASS_STEP_LABEL, BASE_CLASS_STEP_ICON, getIcon, getLabel} from './settings.js'

const DefaultStep = ({
alignment,
Expand All @@ -29,10 +29,12 @@ const DefaultStep = ({
})
return (
<>
<div className={cx(`${BASE_CLASS_STEP}Icon`)}>{resultingIcon}</div>
{showLabel && (
Copy link
Member Author

Choose a reason for hiding this comment

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

☝️

<div className={cx(BASE_CLASS_STEP_ICON)}>{resultingIcon}</div>
{
<div
className={cx(`${BASE_CLASS_STEP}Label`)}
className={cx([BASE_CLASS_STEP_LABEL, `${BASE_CLASS_STEP_LABEL}--step-current-${current}`], {
[`${BASE_CLASS_STEP_LABEL}--visible`]: showLabel
})}
{...(design === DESIGN.COMPRESSED &&
current &&
alignment === ALIGNMENT.HORIZONTAL && {
Expand All @@ -50,7 +52,7 @@ const DefaultStep = ({
>
{getLabel({steps, step, design, label, current})}
</div>
)}
}
</>
)
}
Expand Down
45 changes: 34 additions & 11 deletions components/molecule/stepper/src/Step/index.scss
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
@use 'sass:math';

$base-class-step: #{$base-class}Step;
$base-class-step-label: #{$base-class-step}Label;

#{$base-class-step} {
box-sizing: content-box;
Expand All @@ -16,13 +17,13 @@ $base-class-step: #{$base-class}Step;
color: $c-gray-light;
}
}
#{$base-class-step}Label {
#{$base-class-step-label} {
color: $c-gray-dark-2;
}

&--design {
&-default {
#{$base-class-step}Label {
#{$base-class-step-label} {
width: 100px;
display: flex;
align-items: center;
Expand Down Expand Up @@ -67,16 +68,22 @@ $base-class-step: #{$base-class}Step;
&#{$base-class-step}--alignment {
&-vertical {
max-height: 6 * $sz-base;
#{$base-class-step}Label {
#{$base-class-step-label} {
text-align: start;
justify-content: flex-start;
&:not(#{$base-class-step-label}--visible) {
display: none;
}
}
}
&-horizontal {
max-width: 6 * $sz-base;
#{$base-class-step}Label {
#{$base-class-step-label} {
text-align: center;
justify-content: center;
&:not(#{$base-class-step-label}--visible) {
display: none;
}
}
}
}
Expand Down Expand Up @@ -112,26 +119,36 @@ $base-class-step: #{$base-class}Step;
width: $sz-base;
height: 100%;
}
#{$base-class-step}Label {
#{$base-class-step-label} {
transform: rotate(180deg);
writing-mode: vertical-rl;
text-orientation: mixed;
height: max-content;
width: calc(math.div($w-stepper-label, 2) - $sz-base * 2);
display: flex;
display: none;
align-items: flex-end;
&#{$base-class-step-label}--step-current-true {
&#{$base-class-step-label}--visible {
display: flex;
}
}
}
}
&-horizontal {
width: math.div($w-stepper-label, 2);
flex-direction: column-reverse;
align-items: flex-start;
gap: $sz-base;
#{$base-class-step}Label {
#{$base-class-step-label} {
align-items: flex-end;
display: flex;
display: none;
height: calc(math.div($w-stepper-label, 2) - $sz-base * 2);
width: max-content;
&#{$base-class-step-label}--step-current-true {
&#{$base-class-step-label}--visible {
display: flex;
}
}
}
#{$base-class-step}Icon {
width: 100%;
Expand Down Expand Up @@ -172,7 +189,7 @@ $base-class-step: #{$base-class}Step;
#{$base-class-step}Icon {
background-color: $c-stepper-visited;
}
#{$base-class-step}Label {
#{$base-class-step-label} {
color: $c-stepper-visited;
}
}
Expand All @@ -185,23 +202,29 @@ $base-class-step: #{$base-class}Step;
width: $sz-base;
height: 100%;
}
#{$base-class-step}Label {
#{$base-class-step-label} {
transform: rotate(180deg);
writing-mode: vertical-rl;
text-orientation: mixed;
width: calc(math.div($w-stepper-label, 2) - $sz-base * 2);
display: flex;
align-items: flex-end;
&:not(#{$base-class-step-label}--visible) {
display: none;
}
}
}
&-horizontal {
width: math.div($w-stepper-label, 2);
flex-direction: column-reverse;
gap: $sz-base;
#{$base-class-step}Label {
#{$base-class-step-label} {
height: calc(math.div($w-stepper-label, 2) - $sz-base * 2);
display: flex;
align-items: flex-end;
&:not(#{$base-class-step-label}--visible) {
display: none;
}
}
#{$base-class-step}Icon {
width: 100%;
Expand Down
10 changes: 9 additions & 1 deletion components/molecule/stepper/src/Step/settings.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import {BASE_CLASS, DESIGN} from '../settings.js'

export const BASE_CLASS_STEP = `${BASE_CLASS}Step`
export const BASE_CLASS_STEP_LABEL = `${BASE_CLASS_STEP}Label`
export const BASE_CLASS_STEP_ICON = `${BASE_CLASS_STEP}Icon`

export const getIcon = ({
design,
Expand All @@ -27,5 +29,11 @@ export const getIcon = ({
export const getLabel = ({label, steps, step, design, current}) => {
if (design === DESIGN.DEFAULT) return label
if (design === DESIGN.BASIC) return label
if (design === DESIGN.COMPRESSED && current) return `${step}/${steps}${label ? `: ${label}` : ''}`
if (design === DESIGN.COMPRESSED)
return (
<>
<span>{`${step}/${steps}`}</span>
{label && <span>:&nbsp;{label}</span>}
</>
)
}
Loading