(props: AtlasTreeProps)
| 142 | } |
| 143 | |
| 144 | export default function AtlasTree(props: AtlasTreeProps): JSX.Element { |
| 145 | const listRef = useRef<HTMLUListElement | null>(null); |
| 146 | |
| 147 | // Den Cursor im Blick behalten. Ohne das wandert er beim Tippen aus dem |
| 148 | // sichtbaren Bereich und der Baum sieht aus, als reagiere er nicht. |
| 149 | useEffect(() => { |
| 150 | const list = listRef.current; |
| 151 | if (list === null) { |
| 152 | return; |
| 153 | } |
| 154 | const row = list.querySelector<HTMLElement>('[data-cursor="true"]'); |
| 155 | // jsdom kennt scrollIntoView nicht. Das ist kein Grund, den Baum nicht |
| 156 | // zu pruefen, und kein Grund, jsdom eine Funktion unterzuschieben, die |
| 157 | // der Browser anders macht. |
| 158 | if (typeof row?.scrollIntoView === 'function') { |
| 159 | row.scrollIntoView({ block: 'nearest' }); |
| 160 | } |
| 161 | }, [props.cursor, props.rows.length]); |
| 162 | |
| 163 | return ( |
| 164 | <aside className="atlas-tree" data-testid="atlas-tree"> |
| 165 | <h2 className="atlas-tree-title">{messages.explorer.title}</h2> |
| 166 | <ul |
| 167 | className="atlas-tree-list" |
| 168 | ref={listRef} |
| 169 | role="tree" |
| 170 | aria-label={messages.explorer.title} |
| 171 | tabIndex={0} |
| 172 | onKeyDown={props.onKeyDown} |
| 173 | > |
| 174 | <li> |
| 175 | <span className="atlas-tree-row" data-kind="dir" data-root="true"> |
| 176 | <span className="atlas-tree-twisty">{'▾'}</span> |
| 177 | {props.projectName}/ |
| 178 | </span> |
| 179 | </li> |
| 180 | {props.rows.map((row, index) => { |
| 181 | const state = coverageOf(row); |
| 182 | const mark = markFor(row); |
| 183 | return ( |
| 184 | <li key={row.path} role="treeitem" aria-selected={row.path === props.activePath}> |
| 185 | <Hint name="tree-row" text={titleFor(row)}> |
| 186 | <button |
| 187 | type="button" |
| 188 | tabIndex={-1} |
| 189 | className="atlas-tree-row" |
| 190 | style={{ paddingLeft: `${8 + row.depth * 12}px` }} |
| 191 | data-kind={row.kind} |
| 192 | data-path={row.path} |
| 193 | data-active={row.path === props.activePath} |
| 194 | data-cursor={index === props.cursor} |
| 195 | data-coverage={state} |
| 196 | // Nur fuer Ordner eine Aussage. Bei einer Datei |
| 197 | // waere "nicht aufgeklappt" keine Lage, sondern |
| 198 | // eine Kategorie, die es nicht gibt. |
| 199 | data-expanded={row.kind === 'dir' ? row.expanded : undefined} |
| 200 | data-testid="atlas-tree-row" |
| 201 | onClick={() => { |
nothing calls this directly
no test coverage detected