From a01b53ca38fa1ea1a61f4af7a6fb3d83d6bf7a8d Mon Sep 17 00:00:00 2001 From: Nick Milton Date: Wed, 8 May 2024 16:07:53 -0400 Subject: [PATCH] feat(treeview): handle aria-expanded true on load See #268 --- docs/api/treeview-toggle.md | 24 ++- src/treeviewToggle.js | 64 ++++++++ tests/menus/TreeviewToggle/protected.test.js | 164 ++++++++++++++++++- 3 files changed, 244 insertions(+), 8 deletions(-) diff --git a/docs/api/treeview-toggle.md b/docs/api/treeview-toggle.md index ec56c08..37a6372 100644 --- a/docs/api/treeview-toggle.md +++ b/docs/api/treeview-toggle.md @@ -37,7 +37,15 @@ The constructor will call [BaseMenuToggle's constructor](./base-menu-toggle#cons ## Initialize -The initialize method is inherited from the [BaseMenuToggle](./base-menu-toggle#initialize) class. There are no customizations for the TreeviewToggle class. +Initializes the menu toggle. + +```js +TreeviewToggle.initialize(); +``` + +The first steps are to ensure that the toggle and controlled menu have IDs using the [setIds](./base-menu-toggle#method--setIds) method, and to set the ARIA attributes on the toggle and controlled menu using the [setAriaAttributes](#method--setAriaAttributes) method. + +Then the [open](./base-menu-toggle#method--open) or [collapse](./base-menu-toggle#method--collapse) method is called based on the state of the toggle's aria-expanded attribute. ## Properties @@ -49,4 +57,16 @@ Getters and setters are inherited from the [BaseMenuToggle](./base-menu-toggle#g ## Methods -Methods are inherited from the [BaseMenuToggle](./base-menu-toggle#methods) class. There are no custom methods for the TreeviewToggle class. +Methods are inherited from the [BaseMenuToggle](./base-menu-toggle#methods) class. The following methods are unique to or overwritten in the TreeviewToggle class. + +### _setAriaAttributes {#method--setAriaAttributes} + +Sets the ARIA attributes on the toggle and controlled menu. + +```js +TreeviewToggle._setAriaAttributes(); +``` + +The first steps are to ensure that the toggle has `aria-haspopup` set to "true", `aria-expanded` set to "false" if it's not already set explicitly to "true", and if the toggle element is not a `