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

Set outlineStyle instead of outline when preventing outline #8917

Merged
merged 1 commit into from
Apr 12, 2023
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
19 changes: 10 additions & 9 deletions spec/suites/dom/DomUtilSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -288,22 +288,23 @@ describe('DomUtil', () => {
describe('#preventOutline, #restoreOutline', () => {
it('prevent / restore outline for the element', () => {
const child = document.createElement('div');
el.appendChild(child);
const originalStyle = child.style.outlineStyle = 'dotted';

child.tabIndex = 0;
expect(child.style.outline).to.be.equal(child.style.outline);
el.appendChild(child);

L.DomUtil.preventOutline(child);
expect(child.style.outline).to.match(/(?:none)/);
expect(child.style.outlineStyle).to.equal('none');

// Explicit #restoreOutline through direct call
expect(child.style.outline).to.match(/(?:none)/);
// Explicit #restoreOutline through direct call
L.DomUtil.restoreOutline(child);
expect(child.style.outline).to.be.equal(child.style.outline);
expect(child.style.outlineStyle).to.be.equal(originalStyle);

// Implicit #restoreOutline test through simulation
// Implicit #restoreOutline test through simulation
L.DomUtil.preventOutline(child);
expect(child.style.outline).to.match(/(?:none)/);
expect(child.style.outlineStyle).to.equal('none');
UIEventSimulator.fire('keydown', child);
expect(child.style.outline).to.be.equal(child.style.outline);
expect(child.style.outlineStyle).to.be.equal(originalStyle);
});
});
});
6 changes: 3 additions & 3 deletions src/dom/DomUtil.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,16 +134,16 @@ export function preventOutline(element) {
if (!element.style) { return; }
restoreOutline();
_outlineElement = element;
_outlineStyle = element.style.outline;
element.style.outline = 'none';
_outlineStyle = element.style.outlineStyle;
element.style.outlineStyle = 'none';
DomEvent.on(window, 'keydown', restoreOutline);
}

// @function restoreOutline()
// Cancels the effects of a previous [`L.DomUtil.preventOutline`](#domutil-preventoutline).
export function restoreOutline() {
if (!_outlineElement) { return; }
_outlineElement.style.outline = _outlineStyle;
_outlineElement.style.outlineStyle = _outlineStyle;
_outlineElement = undefined;
_outlineStyle = undefined;
DomEvent.off(window, 'keydown', restoreOutline);
Expand Down