From 79e27f284b14ebaa220e8844022058a01387fd3d Mon Sep 17 00:00:00 2001 From: kat Date: Mon, 14 Mar 2022 17:12:59 -0700 Subject: [PATCH] perf(Modal): CO-6277: add accessibility attributes --- catalog/pages/adaptive_modal/index.md | 6 +++ catalog/pages/buttons/index.md | 4 ++ .../__snapshots__/index.spec.js.snap | 18 ++++----- src/components/Button/Base.tsx | 9 +++-- .../__snapshots__/index.spec.js.snap | 16 ++++++++ src/components/Modal/index.js | 40 ++++++++++++++++--- 6 files changed, 76 insertions(+), 17 deletions(-) diff --git a/catalog/pages/adaptive_modal/index.md b/catalog/pages/adaptive_modal/index.md index de9ae1867..4adba1226 100644 --- a/catalog/pages/adaptive_modal/index.md +++ b/catalog/pages/adaptive_modal/index.md @@ -48,6 +48,12 @@ rows: - Prop: onScroll Type: func(Event) Notes: Optional. Callback is fired when the user scrolls modal's content + - Prop: focusElement + Type: React ref + Notes: Optional. Focuses on referenced element when modal is opened. + - Prop: modalId + Type: string + Notes: Optional. Sets ids of modal's title and content elements as modalId followed by '-title' and '-content' respectively. ``` ```react diff --git a/catalog/pages/buttons/index.md b/catalog/pages/buttons/index.md index d50ff5980..804416a78 100644 --- a/catalog/pages/buttons/index.md +++ b/catalog/pages/buttons/index.md @@ -30,6 +30,10 @@ rows: Type: any Default: Notes: Passes through any other props to underlying button, or in the case of an href prop being passed, anchor, element + - Prop: forwardedRef + Type: any + Default: null + Notes: React ref forwarded to button element. ``` ### Standard button diff --git a/src/components/Banner/__tests__/__snapshots__/index.spec.js.snap b/src/components/Banner/__tests__/__snapshots__/index.spec.js.snap index fa8f5f544..f187b3567 100644 --- a/src/components/Banner/__tests__/__snapshots__/index.spec.js.snap +++ b/src/components/Banner/__tests__/__snapshots__/index.spec.js.snap @@ -107,7 +107,7 @@ exports[` renders correctly when open 1`] = ` This is your primary message text.
renders correctly when variant is set 1`] = ` This is your primary message text.
renders correctly with close button 1`] = ` This is your primary message text.
renders correctly with close button hidden 1`] = ` This is your primary message text.
renders correctly with content 1`] = ` This is your primary message text.
renders correctly with custom icon 1`] = ` This is your primary message text.
renders correctly with custom title for the close button 1`] test link text
renders correctly with expand/collapse button 1`] = ` collapsedText
renders correctly with link 1`] = ` test link text
{ variant: PropTypes.oneOf(BUTTON_VARIANTS), size: PropTypes.oneOf(SIZES), icon: PropTypes.node, - children: PropTypes.node.isRequired + children: PropTypes.node.isRequired, + forwardedRef: PropTypes.objectOf(PropTypes.any) }; static defaultProps: ButtonProps = { size: REGULAR, variant: STANDARD, - icon: null + icon: null, + forwardedRef: null }; componentDidMount() { @@ -78,7 +81,7 @@ class Button extends Component { } }; - button = React.createRef(); + button = this.props.forwardedRef || React.createRef(); render() { const { variant, size, icon, children, ...rest } = this.props; diff --git a/src/components/Modal/__tests__/__snapshots__/index.spec.js.snap b/src/components/Modal/__tests__/__snapshots__/index.spec.js.snap index 236f6a3f2..4f779ed75 100644 --- a/src/components/Modal/__tests__/__snapshots__/index.spec.js.snap +++ b/src/components/Modal/__tests__/__snapshots__/index.spec.js.snap @@ -182,7 +182,9 @@ exports[` closeModal should close the modal when the request was approv class="c0 container--overlay" >