@@ -70,57 +70,40 @@ export class ToolbarPattern<V> {
7070 /** The keydown event manager for the toolbar. */
7171 keydown = computed ( ( ) => {
7272 const manager = new KeyboardEventManager ( ) ;
73- manager . options = {
74- preventDefault : false ,
75- stopPropagation : true ,
76- } ;
73+
74+ const activeItem = this . inputs . activeItem ( ) ;
75+ const isRadioButton = activeItem instanceof RadioButtonPattern ;
76+
77+ if ( isRadioButton ) {
78+ manager
79+ . on ( ' ' , ( ) => this . selectRadioButton ( ) )
80+ . on ( 'Enter' , ( ) => this . selectRadioButton ( ) )
81+ . on ( this . altNextKey , ( ) => activeItem ?. group ( ) ?. listBehavior . next ( ) )
82+ . on ( this . altPrevKey , ( ) => activeItem ?. group ( ) ?. listBehavior . prev ( ) ) ;
83+ } else {
84+ manager . on ( this . altNextKey , ( ) => this . listBehavior . next ( ) ) ;
85+ manager . on ( this . altPrevKey , ( ) => this . listBehavior . prev ( ) ) ;
86+ }
7787
7888 return manager
79- . on ( ' ' , ( ) => this . toolbarSelectOverride ( ) )
80- . on ( 'Enter' , ( ) => this . toolbarSelectOverride ( ) )
8189 . on ( this . prevKey , ( ) => this . listBehavior . prev ( ) )
8290 . on ( this . nextKey , ( ) => this . listBehavior . next ( ) )
83- . on ( this . altNextKey , ( ) => {
84- const activeItem = this . inputs . activeItem ( ) ;
85- /** When within a Radio Group, use its navigation */
86- if ( activeItem instanceof RadioButtonPattern && activeItem . group ( ) ) {
87- activeItem . group ( ) ?. listBehavior . next ( ) ;
88- } else {
89- this . listBehavior . next ( ) ;
90- }
91- } )
92- . on ( this . altPrevKey , ( ) => {
93- const activeItem = this . inputs . activeItem ( ) ;
94- /** When within a Radio Group, use its navigation */
95- if ( activeItem instanceof RadioButtonPattern && activeItem . group ( ) ) {
96- activeItem . group ( ) ?. listBehavior . prev ( ) ;
97- } else {
98- this . listBehavior . prev ( ) ;
99- }
100- } )
10191 . on ( 'Home' , ( ) => this . listBehavior . first ( ) )
10292 . on ( 'End' , ( ) => this . listBehavior . last ( ) ) ;
10393 } ) ;
10494
105- toolbarSelectOverride ( ) {
106- const activeItem = this . inputs . activeItem ( ) ;
95+ selectRadioButton ( ) {
96+ const activeItem = this . inputs . activeItem ( ) as RadioButtonPattern < V > ;
10797
108- /** If the active item is a Radio Button, indicate to the group the selection */
109- if ( activeItem instanceof RadioButtonPattern ) {
110- const group = activeItem . group ( ) ;
111- if ( group && ! group . readonly ( ) && ! group . disabled ( ) ) {
112- group . listBehavior . selectOne ( ) ;
113- }
98+ // activeItem must be a radio button
99+ const group = activeItem ! . group ( ) ;
100+ if ( group && ! group . readonly ( ) && ! group . disabled ( ) ) {
101+ group . listBehavior . selectOne ( ) ;
114102 }
115103 }
116104
117105 /** The pointerdown event manager for the toolbar. */
118- pointerdown = computed ( ( ) => {
119- const manager = new PointerEventManager ( ) ;
120-
121- // Default behavior: navigate and select on click.
122- return manager . on ( e => this . goto ( e ) ) ;
123- } ) ;
106+ pointerdown = computed ( ( ) => new PointerEventManager ( ) . on ( e => this . goto ( e ) ) ) ;
124107
125108 /** Navigates to the widget associated with the given pointer event. */
126109 goto ( event : PointerEvent ) {
@@ -129,8 +112,8 @@ export class ToolbarPattern<V> {
129112
130113 if ( item instanceof RadioButtonPattern ) {
131114 const group = item . group ( ) ;
132- if ( group && ! group . readonly ( ) && ! group . disabled ( ) ) {
133- group . listBehavior . goto ( item , { selectOne : true } ) ;
115+ if ( group && ! group . disabled ( ) ) {
116+ group . listBehavior . goto ( item , { selectOne : ! group . readonly ( ) } ) ;
134117 }
135118 } else {
136119 this . listBehavior . goto ( item ) ;
0 commit comments