diff --git a/src/components/UsaDateRangePicker/UsaDateRangePicker.test.js b/src/components/UsaDateRangePicker/UsaDateRangePicker.test.js
index 5a9c3a64..d51d1f37 100644
--- a/src/components/UsaDateRangePicker/UsaDateRangePicker.test.js
+++ b/src/components/UsaDateRangePicker/UsaDateRangePicker.test.js
@@ -118,7 +118,7 @@ describe('UsaDateRangePicker', () => {
)
.as('monthSelectorButton')
.should('have.attr', 'type', 'button')
- .and('have.attr', 'aria-label', `${month}. Click to select month`)
+ .and('have.attr', 'aria-label', `${month}. Select month`)
.and('have.class', 'usa-date-picker__calendar__month-selection')
.and('contain', month)
@@ -127,7 +127,7 @@ describe('UsaDateRangePicker', () => {
)
.as('yearSelectorButton')
.should('have.attr', 'type', 'button')
- .and('have.attr', 'aria-label', `${year}. Click to select year`)
+ .and('have.attr', 'aria-label', `${year}. Select year`)
.and('have.class', 'usa-date-picker__calendar__year-selection')
.and('contain', year)
@@ -209,13 +209,13 @@ describe('UsaDateRangePicker', () => {
cy.get('@monthSelectorButton')
.should('have.attr', 'type', 'button')
- .and('have.attr', 'aria-label', `${month}. Click to select month`)
+ .and('have.attr', 'aria-label', `${month}. Select month`)
.and('have.class', 'usa-date-picker__calendar__month-selection')
.and('contain', month)
cy.get('@yearSelectorButton')
.should('have.attr', 'type', 'button')
- .and('have.attr', 'aria-label', `${year}. Click to select year`)
+ .and('have.attr', 'aria-label', `${year}. Select year`)
.and('have.class', 'usa-date-picker__calendar__year-selection')
.and('contain', year)
@@ -400,13 +400,13 @@ describe('UsaDateRangePicker', () => {
cy.get('@monthSelectorButton')
.should('have.attr', 'type', 'button')
- .and('have.attr', 'aria-label', `${month}. Click to select month`)
+ .and('have.attr', 'aria-label', `${month}. Select month`)
.and('have.class', 'usa-date-picker__calendar__month-selection')
.and('contain', month)
cy.get('@yearSelectorButton')
.should('have.attr', 'type', 'button')
- .and('have.attr', 'aria-label', `${year}. Click to select year`)
+ .and('have.attr', 'aria-label', `${year}. Select year`)
.and('have.class', 'usa-date-picker__calendar__year-selection')
.and('contain', year)
@@ -555,13 +555,13 @@ describe('UsaDateRangePicker', () => {
cy.get('@monthSelectorButton')
.should('have.attr', 'type', 'button')
- .and('have.attr', 'aria-label', `${month}. Click to select month`)
+ .and('have.attr', 'aria-label', `${month}. Select month`)
.and('have.class', 'usa-date-picker__calendar__month-selection')
.and('contain', month)
cy.get('@yearSelectorButton')
.should('have.attr', 'type', 'button')
- .and('have.attr', 'aria-label', `${year}. Click to select year`)
+ .and('have.attr', 'aria-label', `${year}. Select year`)
.and('have.class', 'usa-date-picker__calendar__year-selection')
.and('contain', year)
@@ -718,13 +718,13 @@ describe('UsaDateRangePicker', () => {
cy.get('@monthSelectorButton')
.should('have.attr', 'type', 'button')
- .and('have.attr', 'aria-label', `${month}. Click to select month`)
+ .and('have.attr', 'aria-label', `${month}. Select month`)
.and('have.class', 'usa-date-picker__calendar__month-selection')
.and('contain', month)
cy.get('@yearSelectorButton')
.should('have.attr', 'type', 'button')
- .and('have.attr', 'aria-label', `${year}. Click to select year`)
+ .and('have.attr', 'aria-label', `${year}. Select year`)
.and('have.class', 'usa-date-picker__calendar__year-selection')
.and('contain', year)
@@ -775,13 +775,13 @@ describe('UsaDateRangePicker', () => {
cy.get('@monthSelectorButton')
.should('have.attr', 'type', 'button')
- .and('have.attr', 'aria-label', `${month}. Click to select month`)
+ .and('have.attr', 'aria-label', `${month}. Select month`)
.and('have.class', 'usa-date-picker__calendar__month-selection')
.and('contain', month)
cy.get('@yearSelectorButton')
.should('have.attr', 'type', 'button')
- .and('have.attr', 'aria-label', `${year}. Click to select year`)
+ .and('have.attr', 'aria-label', `${year}. Select year`)
.and('have.class', 'usa-date-picker__calendar__year-selection')
.and('contain', year)
@@ -1028,7 +1028,7 @@ describe('UsaDateRangePicker', () => {
)
.as('monthSelectorButton')
.should('have.attr', 'type', 'button')
- .and('have.attr', 'aria-label', `${month}. Click to select month`)
+ .and('have.attr', 'aria-label', `${month}. Select month`)
.and('have.class', 'usa-date-picker__calendar__month-selection')
.and('contain', month)
@@ -1037,7 +1037,7 @@ describe('UsaDateRangePicker', () => {
)
.as('yearSelectorButton')
.should('have.attr', 'type', 'button')
- .and('have.attr', 'aria-label', `${year}. Click to select year`)
+ .and('have.attr', 'aria-label', `${year}. Select year`)
.and('have.class', 'usa-date-picker__calendar__year-selection')
.and('contain', year)
@@ -1130,13 +1130,13 @@ describe('UsaDateRangePicker', () => {
cy.get('@monthSelectorButton')
.should('have.attr', 'type', 'button')
- .and('have.attr', 'aria-label', `${month}. Click to select month`)
+ .and('have.attr', 'aria-label', `${month}. Select month`)
.and('have.class', 'usa-date-picker__calendar__month-selection')
.and('contain', month)
cy.get('@yearSelectorButton')
.should('have.attr', 'type', 'button')
- .and('have.attr', 'aria-label', `${year}. Click to select year`)
+ .and('have.attr', 'aria-label', `${year}. Select year`)
.and('have.class', 'usa-date-picker__calendar__year-selection')
.and('contain', year)
@@ -1321,13 +1321,13 @@ describe('UsaDateRangePicker', () => {
cy.get('@monthSelectorButton')
.should('have.attr', 'type', 'button')
- .and('have.attr', 'aria-label', `${month}. Click to select month`)
+ .and('have.attr', 'aria-label', `${month}. Select month`)
.and('have.class', 'usa-date-picker__calendar__month-selection')
.and('contain', month)
cy.get('@yearSelectorButton')
.should('have.attr', 'type', 'button')
- .and('have.attr', 'aria-label', `${year}. Click to select year`)
+ .and('have.attr', 'aria-label', `${year}. Select year`)
.and('have.class', 'usa-date-picker__calendar__year-selection')
.and('contain', year)
@@ -1474,13 +1474,13 @@ describe('UsaDateRangePicker', () => {
cy.get('@monthSelectorButton')
.should('have.attr', 'type', 'button')
- .and('have.attr', 'aria-label', `${month}. Click to select month`)
+ .and('have.attr', 'aria-label', `${month}. Select month`)
.and('have.class', 'usa-date-picker__calendar__month-selection')
.and('contain', month)
cy.get('@yearSelectorButton')
.should('have.attr', 'type', 'button')
- .and('have.attr', 'aria-label', `${year}. Click to select year`)
+ .and('have.attr', 'aria-label', `${year}. Select year`)
.and('have.class', 'usa-date-picker__calendar__year-selection')
.and('contain', year)
@@ -1635,13 +1635,13 @@ describe('UsaDateRangePicker', () => {
cy.get('@monthSelectorButton')
.should('have.attr', 'type', 'button')
- .and('have.attr', 'aria-label', `${month}. Click to select month`)
+ .and('have.attr', 'aria-label', `${month}. Select month`)
.and('have.class', 'usa-date-picker__calendar__month-selection')
.and('contain', month)
cy.get('@yearSelectorButton')
.should('have.attr', 'type', 'button')
- .and('have.attr', 'aria-label', `${year}. Click to select year`)
+ .and('have.attr', 'aria-label', `${year}. Select year`)
.and('have.class', 'usa-date-picker__calendar__year-selection')
.and('contain', year)
@@ -1690,13 +1690,13 @@ describe('UsaDateRangePicker', () => {
cy.get('@monthSelectorButton')
.should('have.attr', 'type', 'button')
- .and('have.attr', 'aria-label', `${month}. Click to select month`)
+ .and('have.attr', 'aria-label', `${month}. Select month`)
.and('have.class', 'usa-date-picker__calendar__month-selection')
.and('contain', month)
cy.get('@yearSelectorButton')
.should('have.attr', 'type', 'button')
- .and('have.attr', 'aria-label', `${year}. Click to select year`)
+ .and('have.attr', 'aria-label', `${year}. Select year`)
.and('have.class', 'usa-date-picker__calendar__year-selection')
.and('contain', year)
diff --git a/src/components/UsaRange/UsaRange.stories.js b/src/components/UsaRange/UsaRange.stories.js
index c9bcb8a9..74d78919 100644
--- a/src/components/UsaRange/UsaRange.stories.js
+++ b/src/components/UsaRange/UsaRange.stories.js
@@ -4,6 +4,8 @@ import UsaRange from './UsaRange.vue'
const defaultProps = {
min: UsaRange.props.min.default,
max: UsaRange.props.max.default,
+ unit: UsaRange.props.unit.default,
+ preposition: UsaRange.props.preposition.default,
modelValue: UsaRange.props.modelValue.default,
label: UsaRange.props.label.default,
required: UsaRange.props.required.default,
@@ -22,6 +24,12 @@ export default {
max: {
control: { type: 'number' },
},
+ unit: {
+ control: { type: 'text' },
+ },
+ preposition: {
+ control: { type: 'text' },
+ },
modelValue: {
control: { type: 'text' },
},
@@ -60,6 +68,8 @@ export default {
args: {
min: defaultProps.min,
max: defaultProps.max,
+ unit: defaultProps.unit,
+ preposition: defaultProps.preposition,
modelValue: defaultProps.modelValue,
label: defaultProps.label,
required: defaultProps.required,
@@ -88,6 +98,8 @@ const DefaultTemplate = (args, { argTypes }) => ({
v-bind="$attrs"
:min="min"
:max="max"
+ :unit="unit"
+ :preposition="preposition"
:label="label"
:required="required"
:error="error"
@@ -120,6 +132,16 @@ DefaultValueRange.args = {
}
DefaultValueRange.storyName = 'Default Value'
+export const CustomUnitAndPrepositionRange = DefaultTemplate.bind({})
+CustomUnitAndPrepositionRange.args = {
+ ...defaultProps,
+ label: 'Range label',
+ modelValue: '75',
+ unit: 'degrees',
+ preposition: 'out of a total',
+}
+CustomUnitAndPrepositionRange.storyName = 'Custom Unit and Preposition'
+
export const HintRange = DefaultTemplate.bind({})
HintRange.args = {
...defaultProps,
diff --git a/src/components/UsaRange/UsaRange.test.js b/src/components/UsaRange/UsaRange.test.js
index 831669a0..a061aa4d 100644
--- a/src/components/UsaRange/UsaRange.test.js
+++ b/src/components/UsaRange/UsaRange.test.js
@@ -15,23 +15,27 @@ describe('UsaRange', () => {
hint: () => 'Test hint',
},
})
+ .its('wrapper')
+ .as('wrapper')
cy.get('div.usa-form-group').should('not.have.attr', 'name')
cy.get('label.usa-label').should('have.attr', 'for')
- cy.get('input.usa-range').as('range').should('have.attr', 'id')
- cy.get('@range')
- .should('have.attr', 'name')
- .and('contain', 'test-dropdown-name')
- cy.get('@range').should('have.attr', 'type').and('contain', 'range')
- cy.get('@range').should('have.attr', 'role').and('contain', 'slider')
- cy.get('@range').should('have.attr', 'min').and('contain', 0)
- cy.get('@range').should('have.attr', 'aria-valuemin').and('contain', 0)
- cy.get('@range').should('have.attr', 'max').and('contain', 100)
- cy.get('@range').should('have.attr', 'aria-valuemax').and('contain', 100)
- cy.get('@range').should('have.attr', 'aria-valuenow').and('contain', '')
-
- cy.get('@range').should('have.attr', 'aria-describedby')
+ cy.get('input.usa-range').should('have.attr', 'id')
+ cy.get('input.usa-range')
+ .should('have.attr', 'name', 'test-dropdown-name')
+ .and('have.attr', 'type', 'range')
+ .and('have.attr', 'min', 0)
+ .and('have.attr', 'max', 100)
+ .and('have.attr', 'aria-describedby')
+ cy.get('input.usa-range').should('not.have.attr', 'aria-valuetext')
+
+ // Check for correct default preposition prop value.
+ cy.get('@wrapper')
+ .vue()
+ .then(({ vm }) => {
+ expect(vm.props.preposition).to.equal('of')
+ })
})
it('displays `label`, `hint`, and `error-message` slot content', () => {
@@ -85,6 +89,25 @@ describe('UsaRange', () => {
.and('contain', 'custom-id-hint custom-id-error-message')
})
+ it('`aria-valuetext` attribute has correct text', () => {
+ cy.mount(UsaRange, {
+ props: {
+ modelValue: 10,
+ },
+ })
+ .its('wrapper')
+ .as('wrapper')
+
+ cy.get('input').should('have.attr', 'aria-valuetext', '10 of 100')
+
+ cy.get('@wrapper').invoke('setProps', {
+ unit: 'degrees',
+ preposition: 'at',
+ })
+
+ cy.get('input').should('have.attr', 'aria-valuetext', '10 degrees at 100')
+ })
+
it('add required attribute if `required` prop is true', () => {
cy.mount(UsaRange, {
props: {
diff --git a/src/components/UsaRange/UsaRange.vue b/src/components/UsaRange/UsaRange.vue
index 9f709f59..819733d8 100644
--- a/src/components/UsaRange/UsaRange.vue
+++ b/src/components/UsaRange/UsaRange.vue
@@ -22,6 +22,14 @@ const props = defineProps({
type: Number,
default: 100,
},
+ unit: {
+ type: String,
+ default: '',
+ },
+ preposition: {
+ type: String,
+ default: 'of',
+ },
modelValue: {
type: [String, Number],
default: '',
@@ -83,6 +91,18 @@ const ariaDescribedby = computed(() => {
return ids.length ? ids.join(' ') : null
})
+
+const callout = computed(() => {
+ if (!rangeValue.value && rangeValue.value !== 0) {
+ return null
+ }
+
+ if (props.unit) {
+ return `${rangeValue.value} ${props.unit} ${props.preposition} ${props.max}`
+ }
+
+ return `${rangeValue.value} ${props.preposition} ${props.max}`
+})
@@ -118,12 +138,9 @@ const ariaDescribedby = computed(() => {
class="usa-range"
:class="classes"
type="range"
- role="slider"
:min="min"
:max="max"
- :aria-valuemin="min"
- :aria-valuemax="max"
- :aria-valuenow="rangeValue"
+ :aria-valuetext="callout"
:required="required"
:aria-describedby="ariaDescribedby"
/>
|