Skip to content

Commit

Permalink
Move key => id mapping to directive.
Browse files Browse the repository at this point in the history
React code only supports id attribute.
  • Loading branch information
Liza K committed Jul 18, 2019
1 parent 0d34cd1 commit 4d7dc8b
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,6 @@ export function TopNavMenu(props: Props) {
function renderItems() {
if (!props.config) return;
return props.config.map((menuItem, i) => {
if (menuItem.key && !menuItem.id) {
// Copy key into id, as it's a reserved react propery.
// This is done for 3rd party developer backward compatibility.
// In the future, ID should be used, rather than key.
menuItem.id = menuItem.key;
}
return (
<EuiFlexItem grow={false} key={`nav-menu-${i}`}>
<TopNavMenuItem {...menuItem} />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,6 @@
export type TopNavMenuAction = (anchorElement: EventTarget) => void;

export interface TopNavMenuData {
// key is to be deprecated and replaced with ID.
// It's a reserved React property https://reactjs.org/warnings/special-props.html
key?: string;
id?: string;
label: string;
run: TopNavMenuAction;
Expand Down
10 changes: 9 additions & 1 deletion src/legacy/ui/public/kbn_top_nav/kbn_top_nav2.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,18 @@ module.directive('kbnTopNavV2', () => {
$scope.store = localStorage;
$scope.uiSettings = chrome.getUiSettingsClient();

// Watch the disableButton functions
// Watch config changes
$scope.$watch(() => {
const config = $scope.$eval($attr.config);
return config.map((item) => {
// Copy key into id, as it's a reserved react propery.
// This is done for Angular directive backward compatibility.
// In React only id is recognized.
if (item.key && !item.id) {
item.id = item.key;
}

// Watch the disableButton functions
if (typeof item.disableButton === 'function') {
return item.disableButton();
}
Expand Down

0 comments on commit 4d7dc8b

Please sign in to comment.