Skip to content

Commit

Permalink
fix: refactor of form components to ensure that aria-describedby do…
Browse files Browse the repository at this point in the history
…es not get an leading white-space
  • Loading branch information
tujoworker committed Sep 23, 2020
1 parent 449f9f4 commit 3d08959
Show file tree
Hide file tree
Showing 15 changed files with 68 additions and 40 deletions.
9 changes: 6 additions & 3 deletions packages/dnb-ui-lib/src/components/checkbox/Checkbox.js
Original file line number Diff line number Diff line change
Expand Up @@ -240,9 +240,12 @@ export default class Checkbox extends React.PureComponent {
}

if (showStatus || suffix) {
inputParams['aria-describedby'] = `${
showStatus ? id + '-status' : ''
} ${suffix ? id + '-suffix' : ''}`
inputParams['aria-describedby'] = [
showStatus ? id + '-status' : null,
suffix ? id + '-suffix' : null
]
.filter(Boolean)
.join(' ')
}
if (readOnly) {
inputParams['aria-readonly'] = inputParams.readOnly = true
Expand Down
9 changes: 6 additions & 3 deletions packages/dnb-ui-lib/src/components/date-picker/DatePicker.js
Original file line number Diff line number Diff line change
Expand Up @@ -744,9 +744,12 @@ export default class DatePicker extends React.PureComponent {

const pickerParams = {}
if (showStatus || suffix) {
pickerParams['aria-describedby'] = `${
showStatus ? id + '-status' : ''
} ${suffix ? id + '-suffix' : ''}`
pickerParams['aria-describedby'] = [
showStatus ? id + '-status' : null,
suffix ? id + '-suffix' : null
]
.filter(Boolean)
.join(' ')
}
if (label) {
pickerParams['aria-labelledby'] = id + '-label'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ exports[`DatePicker component have to match snapshot 1`] = `
lang="nb"
>
<span
aria-describedby="date-picker-id-status "
aria-describedby="date-picker-id-status"
className="dnb-date-picker__inner"
>
<AlignmentHelper
Expand Down
9 changes: 6 additions & 3 deletions packages/dnb-ui-lib/src/components/dropdown/Dropdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -504,9 +504,12 @@ class DropdownInstance extends React.PureComponent {
triggerParams['aria-label'] = title
}
if (showStatus || suffix) {
triggerParams['aria-describedby'] = `${
showStatus ? id + '-status' : ''
} ${suffix ? id + '-suffix' : ''}`
triggerParams['aria-describedby'] = [
showStatus ? id + '-status' : null,
suffix ? id + '-suffix' : null
]
.filter(Boolean)
.join(' ')
}

// also used for code markup simulation
Expand Down
9 changes: 6 additions & 3 deletions packages/dnb-ui-lib/src/components/radio/Radio.js
Original file line number Diff line number Diff line change
Expand Up @@ -333,9 +333,12 @@ export default class Radio extends React.PureComponent {
}

if (showStatus || suffix) {
inputParams['aria-describedby'] = `${
showStatus ? id + '-status' : ''
} ${suffix ? id + '-suffix' : ''}`
inputParams['aria-describedby'] = [
showStatus ? id + '-status' : null,
suffix ? id + '-suffix' : null
]
.filter(Boolean)
.join(' ')
}
if (readOnly) {
inputParams['aria-readonly'] = inputParams.readOnly = true
Expand Down
9 changes: 6 additions & 3 deletions packages/dnb-ui-lib/src/components/radio/RadioGroup.js
Original file line number Diff line number Diff line change
Expand Up @@ -211,9 +211,12 @@ export default class RadioGroup extends React.PureComponent {
}

if (showStatus || suffix) {
params['aria-describedby'] = `${showStatus ? id + '-status' : ''} ${
suffix ? id + '-suffix' : ''
}`
params['aria-describedby'] = [
showStatus ? id + '-status' : null,
suffix ? id + '-suffix' : null
]
.filter(Boolean)
.join(' ')
}
if (label) {
params['aria-labelledby'] = id + '-label'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ exports[`Radio component have to match snapshot 1`] = `
>
<input
aria-checked={false}
aria-describedby=" radio-suffix"
aria-describedby="radio-suffix"
checked={false}
className="dnb-radio__input"
direction="horizontal"
Expand Down
13 changes: 7 additions & 6 deletions packages/dnb-ui-lib/src/components/slider/Slider.js
Original file line number Diff line number Diff line change
Expand Up @@ -577,13 +577,14 @@ export default class Slider extends React.PureComponent {
}
}
if (showStatus || suffix) {
rangeParams['aria-describedby'] = `${
showStatus ? id + '-status' : ''
} ${suffix ? id + '-suffix' : ''}`
rangeParams['aria-describedby'] = [
showStatus ? id + '-status' : null,
suffix ? id + '-suffix' : null
]
.filter(Boolean)
.join(' ')
if (isTouchDevice()) {
trackParams['aria-describedby'] = `${
showStatus ? id + '-status' : ''
} ${suffix ? id + '-suffix' : ''}`
trackParams['aria-describedby'] = rangeParams['aria-describedby']
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ exports[`Slider component have to match snapshot 1`] = `
}
>
<input
aria-describedby=" id-suffix"
aria-describedby="id-suffix"
aria-labelledby="id-label"
className="dnb-slider__button-helper"
disabled={false}
Expand Down
9 changes: 6 additions & 3 deletions packages/dnb-ui-lib/src/components/switch/Switch.js
Original file line number Diff line number Diff line change
Expand Up @@ -261,9 +261,12 @@ export default class Switch extends React.PureComponent {
}

if (showStatus || suffix) {
inputParams['aria-describedby'] = `${
showStatus ? id + '-status' : ''
} ${suffix ? id + '-suffix' : ''}`
inputParams['aria-describedby'] = [
showStatus ? id + '-status' : null,
suffix ? id + '-suffix' : null
]
.filter(Boolean)
.join(' ')
}
if (readOnly) {
inputParams['aria-readonly'] = inputParams.readOnly = true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ exports[`Switch component have to match snapshot 1`] = `
>
<input
aria-checked={false}
aria-describedby=" id-suffix"
aria-describedby="id-suffix"
checked={false}
className="dnb-switch__input"
disabled={false}
Expand Down
9 changes: 6 additions & 3 deletions packages/dnb-ui-lib/src/components/textarea/Textarea.js
Original file line number Diff line number Diff line change
Expand Up @@ -288,9 +288,12 @@ export default class Textarea extends React.PureComponent {

// we may considder using: aria-details
if (showStatus || suffix) {
textareaParams['aria-describedby'] = `${
showStatus ? id + '-status' : ''
} ${suffix ? id + '-suffix' : ''}`
textareaParams['aria-describedby'] = [
showStatus ? id + '-status' : null,
suffix ? id + '-suffix' : null
]
.filter(Boolean)
.join(' ')
}
if (readOnly) {
textareaParams['aria-readonly'] = textareaParams.readOnly = true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -391,9 +391,12 @@ export default class ToggleButton extends React.PureComponent {
}

if (showStatus || suffix) {
buttonParams['aria-describedby'] = `${
showStatus ? id + '-status' : ''
} ${suffix ? id + '-suffix' : ''}`
buttonParams['aria-describedby'] = [
showStatus ? id + '-status' : null,
suffix ? id + '-suffix' : null
]
.filter(Boolean)
.join(' ')
}
if (readOnly) {
buttonParams['aria-readonly'] = buttonParams.readOnly = true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -255,9 +255,12 @@ export default class ToggleButtonGroup extends React.PureComponent {
}

if (showStatus || suffix) {
params['aria-describedby'] = `${showStatus ? id + '-status' : ''} ${
suffix ? id + '-suffix' : ''
}`
params['aria-describedby'] = [
showStatus ? id + '-status' : null,
suffix ? id + '-suffix' : null
]
.filter(Boolean)
.join(' ')
}
if (label) {
params['aria-labelledby'] = id + '-label'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ exports[`ToggleButton component have to match snapshot 1`] = `
/>
</AlignmentHelper>
<Button
aria-describedby=" toggle-button-suffix"
aria-describedby="toggle-button-suffix"
aria-pressed="false"
bounding={false}
class={null}
Expand Down Expand Up @@ -111,7 +111,7 @@ exports[`ToggleButton component have to match snapshot 1`] = `
wrap={false}
>
<button
aria-describedby=" toggle-button-suffix"
aria-describedby="toggle-button-suffix"
aria-pressed="false"
className="dnb-button dnb-button--secondary dnb-button--has-text dnb-toggle-button__button dnb-button--icon-position-left dnb-button--has-icon dnb-button--icon-size-icon_size"
disabled={false}
Expand All @@ -123,7 +123,7 @@ exports[`ToggleButton component have to match snapshot 1`] = `
type="button"
>
<Content
aria-describedby=" toggle-button-suffix"
aria-describedby="toggle-button-suffix"
aria-pressed="false"
bounding={false}
class={null}
Expand Down

0 comments on commit 3d08959

Please sign in to comment.