Skip to content

Commit

Permalink
Merge pull request #1768 from kaliber5/modal-title-id
Browse files Browse the repository at this point in the history
Fix broken aria-labelledby attribute of modals
  • Loading branch information
simonihmig committed Mar 18, 2022
2 parents 87fc68d + 855fedd commit 86390e0
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
3 changes: 2 additions & 1 deletion addon/components/bs-modal/dialog.js
Expand Up @@ -5,6 +5,7 @@ import { next } from '@ember/runloop';
import deprecateSubclassing from 'ember-bootstrap/utils/deprecate-subclassing';
import { ref } from 'ember-ref-bucket';
import { tracked } from '@glimmer/tracking';
import { guidFor } from '@ember/object/internals';

/**
Internal component for modal's markup and event handling. Should not be used directly.
Expand Down Expand Up @@ -64,7 +65,7 @@ export default class ModalDialog extends Component {
nodeId = titleNode.id;
if (!nodeId) {
//no title id so we set one
nodeId = `${this.id}-title`;
nodeId = `${guidFor(this)}-title`;
titleNode.id = nodeId;
}
}
Expand Down
3 changes: 2 additions & 1 deletion tests/integration/components/bs-modal-simple-test.js
Expand Up @@ -611,10 +611,11 @@ module('Integration | Component | bs-modal-simple', function (hooks) {
assert.dom('.modal-dialog').hasClass('modal-dialog-centered');
});

test('Modal has accesibility attributes with default title', async function (assert) {
test('Modal has accessibility attributes with default title', async function (assert) {
await render(hbs`<BsModalSimple @open={{true}} @title="Simple Dialog">Hello world!</BsModalSimple>`);

const modalTitleId = document.getElementsByClassName('modal-title')[0].id;
assert.notOk(modalTitleId.includes('undefined'), 'Should have a proper ID');
assert.dom('.modal').exists({ count: 1 }, 'Modal exists.');
assert.dom('.modal').hasAttribute('role', 'dialog');
assert.dom('.modal-dialog').hasAttribute('role', 'document');
Expand Down

0 comments on commit 86390e0

Please sign in to comment.