Skip to content

Commit

Permalink
fix: remove ARIA attributes when time-picker has no dropdown (#7560) (#…
Browse files Browse the repository at this point in the history
…7563)

Co-authored-by: Serhii Kulykov <[email protected]>
  • Loading branch information
vaadin-bot and web-padawan authored Jul 18, 2024
1 parent 8eed5eb commit 9238b3e
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 1 deletion.
20 changes: 19 additions & 1 deletion packages/time-picker/src/vaadin-time-picker.js
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,10 @@ class TimePicker extends PatternMixin(InputControlMixin(ThemableMixin(ElementMix
}

static get observers() {
return ['__updateDropdownItems(i18n.*, min, max, step)'];
return [
'__updateAriaAttributes(__dropdownItems, opened, inputElement)',
'__updateDropdownItems(i18n.*, min, max, step)',
];
}

static get constraints() {
Expand Down Expand Up @@ -631,6 +634,21 @@ class TimePicker extends PatternMixin(InputControlMixin(ThemableMixin(ElementMix
}
}

/** @private */
__updateAriaAttributes(items, opened, input) {
if (items === undefined || input === undefined) {
return;
}

if (items.length === 0) {
input.removeAttribute('role');
input.removeAttribute('aria-expanded');
} else {
input.setAttribute('role', 'combobox');
input.setAttribute('aria-expanded', !!opened);
}
}

/** @private */
__generateDropdownList(minSec, maxSec, step) {
if (step < 15 * 60 || !this.__validDayDivisor(step)) {
Expand Down
26 changes: 26 additions & 0 deletions packages/time-picker/test/aria.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,30 @@ describe('ARIA', () => {
expect(items[1].getAttribute('aria-selected')).to.equal('true');
});
});

describe('step', () => {
it('should not set role to combo-box when step is less than 900 seconds', () => {
timePicker.step = 600;
expect(input.hasAttribute('role')).to.be.false;
});

it('should restore role to combo-box when step is set back to bigger value', () => {
timePicker.step = 600;

timePicker.step = 900;
expect(input.getAttribute('role')).to.be.equal('combobox');
});

it('should remove aria-expanded attribute when step is less than 900 seconds', () => {
timePicker.step = 600;
expect(input.hasAttribute('aria-expanded')).to.be.false;
});

it('should restore aria-expanded attribute when step is set back to bigger value', () => {
timePicker.step = 600;

timePicker.step = 900;
expect(input.getAttribute('aria-expanded')).to.be.equal('false');
});
});
});

0 comments on commit 9238b3e

Please sign in to comment.