forked from angular/components
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(cdk/tree): add injectable key manager and opt-out
Make backwards compatibility improvements to cdk-tree-revamp regarding focus management, the key manager and tabindex attribute. * Add TreeKeyMangerStrategy interface * Add injection toekn for tree key manager * Add LegacyTreeKeyManager Provide LegacyTreeKeyManager to use legacy tabindex behavior from before TreeKeyManager was introducted. This commit message will be squashed away.
- Loading branch information
Showing
19 changed files
with
943 additions
and
205 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
import {Subject} from 'rxjs'; | ||
import { | ||
TREE_KEY_MANAGER, | ||
TreeKeyManagerFactory, | ||
TreeKeyManagerItem, | ||
TreeKeyManagerStrategy, | ||
} from './tree-key-manager'; | ||
|
||
/** | ||
* @docs-private | ||
* | ||
* @deprecated LegacyTreeKeyManager deprecated. Use TreeKeyManager or inject a | ||
* TreeKeyManagerStrategy instead. To be removed in a future version. | ||
* | ||
* @breaking-change 19.0.0 | ||
*/ | ||
// LegacyTreeKeyManager is a "noop" implementation of TreeKeyMangerStrategy. Methods are noops. Does | ||
// not emit to streams. | ||
// | ||
// Used for applications built before TreeKeyManager to opt-out of TreeKeyManager and revert to | ||
// legacy behavior. | ||
export class LegacyTreeKeyManager<T extends TreeKeyManagerItem> | ||
implements TreeKeyManagerStrategy<T> | ||
{ | ||
get _isLegacyTreeKeyManager() { | ||
return true; | ||
} | ||
|
||
// Provide change as required by TreeKeyManagerStrategy. LegacyTreeKeyManager is a "noop" | ||
// implementation that does not emit to streams. | ||
readonly change = new Subject<T | null>(); | ||
|
||
onKeydown() { | ||
// noop | ||
} | ||
|
||
getActiveItemIndex() { | ||
// Always return null. LegacyTreeKeyManager is a "noop" implementation that does not maintain | ||
// the active item. | ||
return null; | ||
} | ||
|
||
getActiveItem() { | ||
// Always return null. LegacyTreeKeyManager is a "noop" implementation that does not maintain | ||
// the active item. | ||
return null; | ||
} | ||
|
||
onInitialFocus() { | ||
// noop | ||
} | ||
|
||
focusItem() { | ||
// noop | ||
} | ||
|
||
setActiveItem() { | ||
// noop | ||
} | ||
} | ||
|
||
/** | ||
* @docs-private | ||
* | ||
* @deprecated LegacyTreeKeyManager deprecated. Use TreeKeyManager or inject a | ||
* TreeKeyManagerStrategy instead. To be removed in a future version. | ||
* | ||
* @breaking-change 19.0.0 | ||
*/ | ||
export function LEGACY_TREE_KEY_MANAGER_FACTORY< | ||
T extends TreeKeyManagerItem, | ||
>(): TreeKeyManagerFactory<T> { | ||
return () => new LegacyTreeKeyManager<T>(); | ||
} | ||
|
||
/** | ||
* @docs-private | ||
* | ||
* @deprecated LegacyTreeKeyManager deprecated. Use TreeKeyManager or inject a | ||
* TreeKeyManagerStrategy instead. To be removed in a future version. | ||
* | ||
* @breaking-change 19.0.0 | ||
*/ | ||
export const LEGACY_TREE_KEY_MANAGER_FACTORY_PROVIDER = { | ||
provide: TREE_KEY_MANAGER, | ||
useFactory: LEGACY_TREE_KEY_MANAGER_FACTORY, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.