Improve usability of GlDisclosure and its documentation
Problem
While working on Migrate away from the newly deprecated GlNav an... (customers-gitlab-com#10402 - closed) I discovered that the GlDisclosureDropdown component and its instructions weren't easily usable. A few issues came up:
- The documentation is created in a dynamic manner, making it difficult to decipher what exactly is necessary to get the desired behavior. Most examples are based on a dynamic
makeBindings-function. Example: customers-gitlab-com#10402 (comment 2078979772). - There is no example for the declarative approach, which is a supported feature
- You can't set attributes directly in the
disclosure_dropdown_item.vue, but have to create anobjectwith attributes to pass. Example: https://gitlab.com/gitlab-org/customers-gitlab-com/-/merge_requests/10762/diffs#c7500932b6a3a045a1fc967631c0f40fc46f0207_120_120 - Text needs to be passed as an attribute instead of it being possible to pass in the default slot. Example: https://gitlab.com/gitlab-org/customers-gitlab-com/-/merge_requests/10762/diffs#c7500932b6a3a045a1fc967631c0f40fc46f0207_120_122
-
variant=smalldoesn't work forGlLink. This is class is necessary to override the settings: https://gitlab.com/gitlab-org/customers-gitlab-com/-/merge_requests/10762/diffs#c7500932b6a3a045a1fc967631c0f40fc46f0207_53_51 - Test with this component will fail unless a "mock intersection observer" is set up. More context here: https://gitlab.com/gitlab-org/customers-gitlab-com/-/merge_requests/10960#note_2135378960
Context: customers-gitlab-com#10402 (comment 2078979772).
Proposed solution
To improve the situation on the items above, I believe we should do a few updates:
- Make the documentation less dynamic, so examples can be copied and used directly. If we want to remove repetitive code, we should make sure it is displayed in full for the example.
- Add examples of declarative use. This will ensure that it is intuitive to use and thought of, when iterating the component.
- Following the above, we should update the
disclosure_dropdown_item.vueto take separate attributes instead of a single prop,item, and add a default slot where text (content) is added. - Update
disclosure_dropdown_item.vue, so it works withvariant=smallforGlLink. - Describe how to test with this component using a "mock intersection observer".
Edited by Michael Lunøe