From b5d5e2d5b050206ff66da4b0864912ac1f517ede Mon Sep 17 00:00:00 2001 From: Alaa Yahia <6881345+alaa-yahia@users.noreply.github.com> Date: Wed, 29 May 2024 11:46:39 +0300 Subject: [PATCH] feat(FileListItem): accessibility improvements for FileListItem (#1474) --- .../src/file-list/file-list-item.js | 179 ++++++++++-------- 1 file changed, 98 insertions(+), 81 deletions(-) diff --git a/components/file-input/src/file-list/file-list-item.js b/components/file-input/src/file-list/file-list-item.js index eae111a07d..71eaa160a4 100644 --- a/components/file-input/src/file-list/file-list-item.js +++ b/components/file-input/src/file-list/file-list-item.js @@ -14,91 +14,108 @@ const FileListItem = ({ onCancel, cancelText, dataTest, -}) => ( -

- - {loading ? ( - - ) : ( - - )} - +}) => { + const handleKeyDown = (event) => { + if (!onRemove) { + return + } + if ( + event.key === 'Enter' || + event.key === 'Backspace' || + event.key === 'Delete' + ) { + onRemove({}, event) + } + } - - {label} + return ( +

+ + {loading ? ( + + ) : ( + + )} + - {loading && onCancel && cancelText && ( - onCancel({}, event)} - data-test={`${dataTest}-cancel`} - > - {cancelText} - - )} + + {label} - {!loading && ( - onRemove({}, event)} - data-test={`${dataTest}-remove`} - > - {removeText} - - )} - + {loading && onCancel && cancelText && ( + onCancel({}, event)} + data-test={`${dataTest}-cancel`} + > + {cancelText} + + )} - -

-) + {!loading && ( + onRemove({}, event)} + data-test={`${dataTest}-remove`} + tabIndex={0} + onKeyDown={handleKeyDown} + > + {removeText} + + )} + + + +

+ ) +} FileListItem.defaultProps = { dataTest: 'dhis2-uicore-filelistitem',