-
Notifications
You must be signed in to change notification settings - Fork 3.6k
/
listitemgroupview.ts
120 lines (100 loc) · 2.94 KB
/
listitemgroupview.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
/**
* @license Copyright (c) 2003-2024, CKSource Holding sp. z o.o. All rights reserved.
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
*/
/**
* @module ui/list/listitemgroupview
*/
import View from '../view.js';
import type ViewCollection from '../viewcollection.js';
import ListView from './listview.js';
import type ListItemView from './listitemview.js';
import LabelView from '../label/labelview.js';
import ListSeparatorView from './listseparatorview.js';
import { type Locale } from '@ckeditor/ckeditor5-utils';
/**
* The list item group view class.
*/
export default class ListItemGroupView extends View {
/**
* The visible label of the group.
*
* @observable
* @default ''
*/
declare public label: string;
/**
* Label of the group view. Its text is configurable using the {@link #label label attribute}.
*
* If a custom label view is not passed in `ListItemGroupView` constructor, the label is an instance
* of {@link module:ui/label/labelview~LabelView}.
*/
public readonly labelView: LabelView;
/**
* Collection of the child list items inside this group.
*/
public readonly items: ListView[ 'items' ];
/**
* Collection of the child elements of the group.
*/
public readonly children: ViewCollection;
/**
* Controls whether the item view is visible. Visible by default, list items are hidden
* using a CSS class.
*
* @observable
* @default true
*/
declare public isVisible: boolean;
/**
* Creates an instance of the list item group view class.
*
* @param locale The {@link module:core/editor/editor~Editor#locale} instance.
* @param labelView The instance of the group's label. If not provided, an instance of
* {@link module:ui/label/labelview~LabelView} is used.
*/
constructor( locale?: Locale, labelView: LabelView = new LabelView() ) {
super( locale );
const bind = this.bindTemplate;
const nestedList = new ListView( locale );
this.set( {
label: '',
isVisible: true
} );
this.labelView = labelView;
this.labelView.bind( 'text' ).to( this, 'label' );
this.children = this.createCollection();
this.children.addMany( [ this.labelView, nestedList ] );
nestedList.set( {
role: 'group',
ariaLabelledBy: labelView.id
} );
// Disable focus tracking and accessible navigation in the child list.
nestedList.focusTracker.destroy();
nestedList.keystrokes.destroy();
this.items = nestedList.items;
this.setTemplate( {
tag: 'li',
attributes: {
role: 'presentation',
class: [
'ck',
'ck-list__group',
bind.if( 'isVisible', 'ck-hidden', value => !value )
]
},
children: this.children
} );
}
/**
* Focuses the list item (which is not a separator).
*/
public focus(): void {
if ( this.items ) {
const firstListItem = this.items.find( item => !( item instanceof ListSeparatorView ) ) as ListItemView | ListItemGroupView;
if ( firstListItem ) {
firstListItem.focus();
}
}
}
}