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

fix(ui-shell): change the way to generate unique ID #4291

Merged
merged 2 commits into from
Oct 11, 2019
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import on from '../../globals/js/misc/on';
import settings from '../../globals/js/settings';
import onFocusOutByKeyboard from '../../globals/js/misc/on-focus-by-keyboard';

let seq = 0;

export default class ProductSwitcher extends NavigationMenuPanel {
/**
* A navigation menu
Expand Down Expand Up @@ -80,9 +82,7 @@ export default class ProductSwitcher extends NavigationMenuPanel {
);
const launcher = event.delegateTarget;
if (!launcher.id) {
launcher.id = `__carbon-product-switcher-launcher-${Math.random()
.toString(36)
.substr(2)}`;
launcher.id = `__carbon-product-switcher-launcher-${seq++}`;
Copy link
Contributor

@elizabethsjudd elizabethsjudd Oct 10, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FYI, ids must start with a letter in order to be valid HTML. If this is an id that get's added to the HTML I would suggest removing the underscores.

Copy link
Contributor

@joshblack joshblack Oct 10, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it more-so that it was a requirement in HTML4? And they suggest doing it for backwards compat

https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/id

Note: Using characters except ASCII letters, digits, '_', '-' and '.' may cause compatibility problems, as they weren't allowed in HTML 4. Though this restriction has been lifted in HTML5, an ID should start with a letter for compatibility.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Given the point seems for older browsers probably we'd go for it as-is for now.

}
const current = launcher.id;
this.changeState(
Expand Down