[英]How do you set a default focus() on an element
I'm trying to make an Angular Application (uses D3.js) Web Accessible. 我正在尝试使Angular应用程序(使用D3.js)可访问Web。
Goal: When a user calls for a particular chart (in this case a sunburst), the chart expands into view. 目标:当用户要求特定的图表(在这种情况下为森伯斯特)时,该图表会扩展到视图中。 My intention is to create a default focus on a specific element of the chart so once the user calls/selects the chart, the chart will automatically have focus. 我的意图是在图表的特定元素上创建默认焦点,因此一旦用户调用/选择了图表,图表将自动具有焦点。
Problem: Once I expand the sunburst chart into view, the Tabbing order resets from the start of the page (there is no page load as its a Single Page Application). 问题:一旦我将森伯斯特图扩展到视图中,则制表顺序将从页面的开头重置(没有页面加载作为其单页面应用程序)。 Then the user would have to TAB through the whole page to navigate to the sunburst chart. 然后,用户将不得不在整个页面上进行制表以导航到朝阳图。 I have already set the center node to have an attribute of Tabindex:0 . 我已经将中心节点设置为具有Tabindex:0的属性。 So now the center node can be accessed via keyboard navigation (tabbing). 因此,现在可以通过键盘导航(制表符)访问中心节点。
var defaultNode = d3.select(sunburstChartdetail").select("path").attr("tabindex", 0);
I have tried: 我努力了:
defaultNode.focus();
but I get a console error suggesting 'focus' is not a function 但出现控制台错误,提示“焦点”不是功能
NOTE: Unfortunately I cannot post the code for NDA reasons. 注意:不幸的是,由于NDA原因,我无法发布代码。
To focus on an element, you need to get a reference to the underlying DOM element: 为了专注于元素,您需要获取对底层DOM元素的引用:
d3.select("foobar").node().focus()
Or in your case: 或您的情况:
defaultNode.node().focus()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.