diff --git a/components/ChecklistItem/Heading.js b/components/ChecklistItem/Heading.js index 77c9fb5..94122cd 100644 --- a/components/ChecklistItem/Heading.js +++ b/components/ChecklistItem/Heading.js @@ -1,6 +1,6 @@ // @flow import React from 'react'; -import { Title, Description, Uncollapse } from './style'; +import { Title, Uncollapse } from './style'; import type { ChecklistResource } from '../../types'; type Props = { @@ -13,10 +13,13 @@ export const Heading = ({ resource, isCollapsed, handleCollapse }: Props) => ( {resource.title} - <Uncollapse onClick={handleCollapse}> + <Uncollapse + onClick={handleCollapse} + aria-controls={`content_${resource.id}`} + aria-expanded={!isCollapsed} + > {isCollapsed ? 'Show details' : 'Hide details'} </Uncollapse> - {!isCollapsed && } ); diff --git a/components/ChecklistItem/index.js b/components/ChecklistItem/index.js index 5c5ea42..53c1cc8 100644 --- a/components/ChecklistItem/index.js +++ b/components/ChecklistItem/index.js @@ -13,6 +13,8 @@ import { CardContent, ResourceContent, Divider, + Description, + Content, } from './style'; type Props = { @@ -23,10 +25,17 @@ type State = { isChecked: boolean, isLoading: boolean, isCollapsed: boolean, + contentHeight: number, }; class ChecklistItem extends React.Component { - state = { isChecked: false, isLoading: true, isCollapsed: true }; + state = { isChecked: false, isLoading: true, isCollapsed: true, contentHeight: 2000, }; + + constructor(props) { + super(props); + + this.contentContainer = React.createRef(); + } componentDidMount() { const { resource } = this.props; @@ -38,6 +47,15 @@ class ChecklistItem extends React.Component { }); } + componentDidUpdate(prevProps, prevState) { + + if (prevState.isLoading && !this.state.isLoading) { + return this.setState({ + contentHeight: this.contentContainer.current.scrollHeight, + }) + } + } + handleSetChecked = () => { const { isChecked } = this.state; const { resource } = this.props; @@ -45,11 +63,19 @@ class ChecklistItem extends React.Component { return this.setState({ isChecked: !isChecked, isCollapsed: !isChecked }); }; - uncollapse = () => - this.setState(state => ({ isCollapsed: !state.isCollapsed })); + uncollapse = () => { + this.setState(state => ({ isCollapsed: !state.isCollapsed })); + this.contentContainer.current.focus(); + }; + + handleAppsExpand = appsContainerHeight => { + return this.setState({ + contentHeight: this.contentContainer.current.scrollHeight + appsContainerHeight, + }) + } render() { - const { isChecked, isLoading, isCollapsed } = this.state; + const { isChecked, isLoading, isCollapsed, contentHeight } = this.state; const { resource } = this.props; if (isLoading) return ; @@ -60,13 +86,14 @@ class ChecklistItem extends React.Component { - @@ -74,8 +101,6 @@ class ChecklistItem extends React.Component {