diff --git a/packages/terra-core-docs/CHANGELOG.md b/packages/terra-core-docs/CHANGELOG.md index af8ebf9db10..6d095a77a66 100644 --- a/packages/terra-core-docs/CHANGELOG.md +++ b/packages/terra-core-docs/CHANGELOG.md @@ -29,6 +29,7 @@ * Updated * Updated `terra-alert` documentation for custom titles. + * Updated `terra-dropdown-button` documentation for testing uuid details. * Updated exisiting examples upto a11y standards * Fixed diff --git a/packages/terra-core-docs/src/terra-dev-site/doc/dropdown-button/About.1.doc.mdx b/packages/terra-core-docs/src/terra-dev-site/doc/dropdown-button/About.1.doc.mdx index 487780be978..3f6648319ec 100644 --- a/packages/terra-core-docs/src/terra-dev-site/doc/dropdown-button/About.1.doc.mdx +++ b/packages/terra-core-docs/src/terra-dev-site/doc/dropdown-button/About.1.doc.mdx @@ -37,6 +37,11 @@ This component requires the following peer dependencies be installed in your app +## Implementation Notes: +The Form-Field component must be composed inside the [Base][1] component with a locale in order for it to load the correct translation strings. + +[1]: https://engineering.cerner.com/terra-ui/application/terra-application/components/application-base + ## Usage ```jsx @@ -62,3 +67,26 @@ import DropdownButton, { Item } from 'terra-dropdown-button'; ## Item Props + +## Testing + +Terra Dropdown button uses `uuid` which changes the component's description id dynamically. To mock the return value with the Jest testing library, `jest.spyOn` can be used. + +If Enzyme `shallow` is being used for the tests then the mock may not be required depending on the depth of the returned wrapper. However, if `mount` is used then `uuid` should be mocked as shown below: + +```js +import { v4 as uuidv4 } from 'uuid'; + +let mockSpyUuid; + +// using a variable may result in failures. For best results, mock return value. +beforeAll(() => { + mockSpyUuid = jest.spyOn(uuidv4, 'v4').mockReturnValue('00000000-0000-0000-0000-000000000000'); +}); + +// restore the mock +afterAll(() => { + mockSpyUuid.mockRestore(); +}); + +``` diff --git a/packages/terra-core-docs/src/terra-dev-site/doc/dropdown-button/SplitButton.2.doc.mdx b/packages/terra-core-docs/src/terra-dev-site/doc/dropdown-button/SplitButton.2.doc.mdx index 10db89ccf23..5a1d726faed 100644 --- a/packages/terra-core-docs/src/terra-dev-site/doc/dropdown-button/SplitButton.2.doc.mdx +++ b/packages/terra-core-docs/src/terra-dev-site/doc/dropdown-button/SplitButton.2.doc.mdx @@ -25,7 +25,7 @@ Children must be the `Item` subcomponent for proper functionality and appearance ## Implementation Notes: The SplitButton component must be composed inside the [Base][1] component with a locale in order for it to load the correct translation strings. -[1]: https://engineering.cerner.com/terra-core/components/terra-base/base/base +[1]: https://engineering.cerner.com/terra-ui/application/terra-application/components/application-base ## Usage @@ -51,4 +51,27 @@ import { Item, SplitButton } from 'terra-dropdown-button'; ## Item Props - \ No newline at end of file + + +## Testing + +Terra Split Button uses `uuid` which changes the component's description id dynamically. To mock the return value with the Jest testing library, `jest.spyOn` can be used. + +If Enzyme `shallow` is being used for the tests then the mock may not be required depending on the depth of the returned wrapper. However, if `mount` is used then `uuid` should be mocked as shown below: + +```js +import { v4 as uuidv4 } from 'uuid'; + +let mockSpyUuid; + +// using a variable may result in failures. For best results, mock return value. +beforeAll(() => { + mockSpyUuid = jest.spyOn(uuidv4, 'v4').mockReturnValue('00000000-0000-0000-0000-000000000000'); +}); + +// restore the mock +afterAll(() => { + mockSpyUuid.mockRestore(); +}); + +``` \ No newline at end of file diff --git a/packages/terra-dropdown-button/CHANGELOG.md b/packages/terra-dropdown-button/CHANGELOG.md index aad697f2bcc..bd627ddfdae 100644 --- a/packages/terra-dropdown-button/CHANGELOG.md +++ b/packages/terra-dropdown-button/CHANGELOG.md @@ -1,6 +1,9 @@ # Changelog ## Unreleased +* Added + * Added 'aria-haspoup' and 'aria-controls' attributes for dropdown button. + * Added customClass support for dropdown item. ## 1.37.0 - (October 26, 2023) diff --git a/packages/terra-dropdown-button/package.json b/packages/terra-dropdown-button/package.json index 2fbc66a9d96..401b7ae616f 100644 --- a/packages/terra-dropdown-button/package.json +++ b/packages/terra-dropdown-button/package.json @@ -33,7 +33,8 @@ "prop-types": "^15.5.8", "terra-hookshot": "^5.0.0", "terra-mixins": "^1.40.0", - "terra-theme-context": "^1.0.0" + "terra-theme-context": "^1.0.0", + "uuid": "3.4.0" }, "scripts": { "compile": "babel --root-mode upward src --out-dir lib --copy-files", diff --git a/packages/terra-dropdown-button/src/DropdownButton.jsx b/packages/terra-dropdown-button/src/DropdownButton.jsx index 93b57d83115..a9e7d267426 100644 --- a/packages/terra-dropdown-button/src/DropdownButton.jsx +++ b/packages/terra-dropdown-button/src/DropdownButton.jsx @@ -3,6 +3,8 @@ import PropTypes from 'prop-types'; import classNamesBind from 'classnames/bind'; import ThemeContext from 'terra-theme-context'; import * as KeyCode from 'keycode-js'; +// eslint-disable-next-line import/no-extraneous-dependencies +import { v4 as uuidv4 } from 'uuid'; import { injectIntl } from 'react-intl'; import DropdownButtonBase from './_DropdownButtonBase'; import styles from './DropdownButton.module.scss'; @@ -185,6 +187,9 @@ class DropdownButton extends React.Component { const customLabel = (selectText) ? `${selectText}, ${selectedLabel}, ${label}` : label; buttonAriaLabel = `${customLabel}${buttonAriaLabel ? `, ${buttonAriaLabel}` : ''}`; + const dropDownMenuId = uuidv4(); + const dropDownMenuListId = `dropdown-menu-list-${dropDownMenuId}`; + return (