From 6954ba06378156b5aacf4ff6e9c65cc177a3b003 Mon Sep 17 00:00:00 2001 From: "D.A. Kahn" Date: Thu, 18 Mar 2021 13:29:38 -0500 Subject: [PATCH 01/18] fix(StructuredList): refactor instanceId --- .../StructuredList/StructuredList.js | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/packages/react/src/components/StructuredList/StructuredList.js b/packages/react/src/components/StructuredList/StructuredList.js index ac665c0e376a..f2951c4524bb 100644 --- a/packages/react/src/components/StructuredList/StructuredList.js +++ b/packages/react/src/components/StructuredList/StructuredList.js @@ -9,11 +9,10 @@ import React from 'react'; import PropTypes from 'prop-types'; import classNames from 'classnames'; import { settings } from 'carbon-components'; -import setupGetInstanceId from '../../tools/setupGetInstanceId'; +import { useId } from '../../internal/useId'; import deprecate from '../../prop-types/deprecate'; const { prefix } = settings; -const getInstanceId = setupGetInstanceId(); export function StructuredListWrapper(props) { const { @@ -193,21 +192,27 @@ StructuredListRow.propTypes = { StructuredListRow.defaultProps = { head: false, label: false, - tabIndex: 0, onKeyDown: () => {}, }; export function StructuredListInput(props) { - const { className, value, name, title, id, ...other } = props; const classes = classNames(`${prefix}--structured-list-input`, className); - const instanceId = id || getInstanceId(); + const defaultId = useId('structureListInput'); + const { + className, + value, + name = `structuredListInput-${defaultId}`, + title, + id, + ...other + } = props; return ( Date: Tue, 23 Mar 2021 14:42:11 -0500 Subject: [PATCH 02/18] fix(StructuredList): convert to radio interaction, add focus state --- .../structured-list/_structured-list.scss | 8 ++----- .../StructuredList/StructuredList.js | 21 ++++++++++++++++++- 2 files changed, 22 insertions(+), 7 deletions(-) diff --git a/packages/components/src/components/structured-list/_structured-list.scss b/packages/components/src/components/structured-list/_structured-list.scss index d809a858c695..2df36b73405f 100644 --- a/packages/components/src/components/structured-list/_structured-list.scss +++ b/packages/components/src/components/structured-list/_structured-list.scss @@ -18,8 +18,8 @@ @include padding--data-structured-list; } - .#{$prefix}--structured-list-input { - display: none; + .#{$prefix}--structured-list-row--focused-within { + @include focus-outline('outline'); } .#{$prefix}--structured-list { @@ -62,10 +62,6 @@ cursor: inherit; } - .#{$prefix}--structured-list-row:focus:not(.#{$prefix}--structured-list-row--header-row) { - @include focus-outline('outline'); - } - .#{$prefix}--structured-list--selection .#{$prefix}--structured-list-row:hover:not(.#{$prefix}--structured-list-row--header-row) > .#{$prefix}--structured-list-td, diff --git a/packages/react/src/components/StructuredList/StructuredList.js b/packages/react/src/components/StructuredList/StructuredList.js index f2951c4524bb..32eaa1632142 100644 --- a/packages/react/src/components/StructuredList/StructuredList.js +++ b/packages/react/src/components/StructuredList/StructuredList.js @@ -5,7 +5,7 @@ * LICENSE file in the root directory of this source tree. */ -import React from 'react'; +import React, { useState } from 'react'; import PropTypes from 'prop-types'; import classNames from 'classnames'; import { settings } from 'carbon-components'; @@ -126,6 +126,11 @@ StructuredListBody.defaultProps = { onKeyDown: () => {}, }; +function useFocusWithin() { + const [hasFocusWithin, setHasFocusWithin] = useState(false); + return [hasFocusWithin, setHasFocusWithin]; +} + export function StructuredListRow(props) { const { onKeyDown, @@ -136,8 +141,10 @@ export function StructuredListRow(props) { label, ...other } = props; + const [hasFocusWithin, setHasFocusWithin] = useFocusWithin(); const classes = classNames(`${prefix}--structured-list-row`, className, { [`${prefix}--structured-list-row--header-row`]: head, + [`${prefix}--structured-list-row--focused-within`]: hasFocusWithin, }); return label ? ( @@ -146,6 +153,14 @@ export function StructuredListRow(props) { {...other} tabIndex={tabIndex} className={classes} + onFocus={() => { + setHasFocusWithin(true); + }} + onBlur={() => { + // potential special case where when focus is moved this row is not blurred + // multiple interactable per row? + setHasFocusWithin(false); + }} onKeyDown={onKeyDown}> {children} @@ -192,9 +207,13 @@ StructuredListRow.propTypes = { StructuredListRow.defaultProps = { head: false, label: false, + // tabIndex: 0, onKeyDown: () => {}, }; +// when the input gets focus it should add the data- attribute to the parent row +// on blur it should be removed +// that can be targeted export function StructuredListInput(props) { const classes = classNames(`${prefix}--structured-list-input`, className); const defaultId = useId('structureListInput'); From 1f46ed54fb506d9d1d32cd89878f2e7b2d9e3808 Mon Sep 17 00:00:00 2001 From: "D.A. Kahn" Date: Tue, 23 Mar 2021 15:23:11 -0500 Subject: [PATCH 03/18] fix(StructuredList): hide radio input --- .../src/components/StructuredList/StructuredList.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/packages/react/src/components/StructuredList/StructuredList.js b/packages/react/src/components/StructuredList/StructuredList.js index 32eaa1632142..bf5bf77e9b7b 100644 --- a/packages/react/src/components/StructuredList/StructuredList.js +++ b/packages/react/src/components/StructuredList/StructuredList.js @@ -207,15 +207,15 @@ StructuredListRow.propTypes = { StructuredListRow.defaultProps = { head: false, label: false, - // tabIndex: 0, onKeyDown: () => {}, }; -// when the input gets focus it should add the data- attribute to the parent row -// on blur it should be removed -// that can be targeted export function StructuredListInput(props) { - const classes = classNames(`${prefix}--structured-list-input`, className); + const classes = classNames( + `${prefix}--structured-list-input`, + `${prefix}--visually-hidden`, + className + ); const defaultId = useId('structureListInput'); const { className, From f655b31863b71228a0541b61b06da8fd7a33e58f Mon Sep 17 00:00:00 2001 From: "D.A. Kahn" Date: Tue, 23 Mar 2021 17:56:20 -0500 Subject: [PATCH 04/18] fix(StructuredList): remove label and tabIndex props on input --- .../StructuredList/StructuredList.js | 41 +++++-------------- 1 file changed, 10 insertions(+), 31 deletions(-) diff --git a/packages/react/src/components/StructuredList/StructuredList.js b/packages/react/src/components/StructuredList/StructuredList.js index bf5bf77e9b7b..63e859db9449 100644 --- a/packages/react/src/components/StructuredList/StructuredList.js +++ b/packages/react/src/components/StructuredList/StructuredList.js @@ -28,7 +28,7 @@ export function StructuredListWrapper(props) { }); return ( -
+
{children}
); @@ -132,41 +132,32 @@ function useFocusWithin() { } export function StructuredListRow(props) { - const { - onKeyDown, - tabIndex, - children, - className, - head, - label, - ...other - } = props; + const { onKeyDown, children, className, head, ...other } = props; const [hasFocusWithin, setHasFocusWithin] = useFocusWithin(); const classes = classNames(`${prefix}--structured-list-row`, className, { [`${prefix}--structured-list-row--header-row`]: head, [`${prefix}--structured-list-row--focused-within`]: hasFocusWithin, }); - return label ? ( + return head ? ( +
+ {children} +
+ ) : ( // eslint-disable-next-line jsx-a11y/no-noninteractive-element-interactions - - ) : ( -
- {children}
); } @@ -187,26 +178,14 @@ StructuredListRow.propTypes = { */ head: PropTypes.bool, - /** - * Specify whether a `