Skip to content

Commit 575b060

Browse files
committed
added ability to disable front end view of accessibility tree
1 parent fce58c6 commit 575b060

File tree

2 files changed

+70
-5
lines changed

2 files changed

+70
-5
lines changed

src/app/components/StateRoute/StateRoute.tsx

Lines changed: 60 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@
55
/* eslint-disable @typescript-eslint/no-var-requires */
66
/* eslint-disable max-len */
77
/* eslint-disable object-curly-newline */
8-
import React from 'react';
8+
import React, { useState } from 'react';
99
import { MemoryRouter as Router, Route, NavLink, Routes, Outlet, Link } from 'react-router-dom';
1010
import { ParentSize } from '@visx/responsive';
1111
import Tree from './Tree';
1212
import ComponentMap from './ComponentMap/ComponentMap';
13-
import { changeView, changeSlider } from '../../slices/mainSlice';
14-
import { useSelector } from 'react-redux';
13+
import { changeView, changeSlider, toggleAxTree, setCurrentTabInApp } from '../../slices/mainSlice';
14+
import { useDispatch, useSelector } from 'react-redux';
1515
import PerformanceVisx from './PerformanceVisx/PerformanceVisx';
1616
import WebMetricsContainer from './WebMetrics/WebMetricsContainer';
1717
import { MainState, RootState, StateRouteProps } from '../../FrontendTypes';
@@ -35,11 +35,33 @@ const StateRoute = (props: StateRouteProps) => {
3535
currLocation, // from 'tabs[currentTab]' object in 'MainContainer'
3636
} = props;
3737

38+
3839
const { tabs, currentTab }: MainState = useSelector((state: RootState) => state.main);
3940
const { hierarchy: tabsHierarchy, sliderIndex, viewIndex: tabsViewIndex } = tabs[currentTab];
4041
const hierarchy = propsHierarchy || tabsHierarchy;
4142
const viewIndex = propsViewIndex || tabsViewIndex;
4243

44+
const dispatch = useDispatch();
45+
const [showTree, setShowTree] = useState(false);
46+
const [selectedValue, setSelectedValue] = useState('disable');
47+
const [showParagraph, setShowParagraph] = useState(true);
48+
49+
const enableAxTreeButton = () => {
50+
dispatch(toggleAxTree('toggleAxRecord'));
51+
dispatch(setCurrentTabInApp('AxTree'));
52+
setSelectedValue('enable');
53+
setShowParagraph(false);
54+
setShowTree(true);
55+
};
56+
57+
const disableAxTree = () => {
58+
dispatch(toggleAxTree('toggleAxRecord'));
59+
setSelectedValue('disable');
60+
setShowParagraph(true);
61+
setShowTree(false);
62+
};
63+
64+
4365
return (
4466
<div className='app-body'>
4567
<div className='navbar'>
@@ -102,7 +124,7 @@ const StateRoute = (props: StateRouteProps) => {
102124
<Route
103125
path='/accessibility'
104126
element={
105-
hierarchy ? (
127+
showTree ? (
106128
<ParentSize className='componentMapContainer'>
107129
{({ width, height }) => {
108130
// eslint-disable-next-line react/prop-types
@@ -121,7 +143,40 @@ const StateRoute = (props: StateRouteProps) => {
121143
);
122144
}}
123145
</ParentSize>
124-
) : null
146+
) : <div>
147+
{showParagraph && (
148+
<p>
149+
A Note to Developers: Reactime is using the Chrome Debugger API in order to grab the
150+
Accessibility Tree. Enabling this option will allow you to record Accessibility Tree
151+
snapshots, but will result in the Chrome browser notifying you that the Chrome Debugger
152+
has started.
153+
</p>
154+
)}
155+
<div>
156+
{
157+
<input
158+
type='radio'
159+
value='enable'
160+
checked={selectedValue === 'enable'}
161+
onChange={() => {
162+
enableAxTreeButton();
163+
}}
164+
/>
165+
}
166+
<label htmlFor='enable'>Enable</label>
167+
{
168+
<input
169+
type='radio'
170+
value='disable'
171+
checked={selectedValue === 'disable'}
172+
onChange={() => {
173+
disableAxTree();
174+
}}
175+
/>
176+
}
177+
<label htmlFor='disable'>Disable</label>
178+
</div>
179+
</div>
125180
}
126181
></Route>
127182
<Route

src/app/slices/mainSlice.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -506,6 +506,15 @@ export const mainSlice = createSlice({
506506
state.connectRequested = false;
507507
state.connectionStatus = true;
508508
},
509+
510+
toggleAxTree: (state, action) => {
511+
const { port, payload, tabs, currentTab} = state;
512+
port.postMessage({
513+
action: 'toggleAxRecord',
514+
payload: action.payload,
515+
tabId: currentTab,
516+
})
517+
}
509518
},
510519
});
511520

@@ -540,4 +549,5 @@ export const {
540549
disconnected,
541550
startReconnect,
542551
endConnect,
552+
toggleAxTree,
543553
} = mainSlice.actions;

0 commit comments

Comments
 (0)