Skip to content

Commit 9fbfa09

Browse files
committed
[Misc] modular UI panel wcag styling (#9214)
(master → master)
1 parent a1aff56 commit 9fbfa09

File tree

24 files changed

+792
-276
lines changed

24 files changed

+792
-276
lines changed

assets/icons/digital_signature_error.svg

Lines changed: 1 addition & 1 deletion
Loading

assets/icons/digital_signature_valid.svg

Lines changed: 1 addition & 1 deletion
Loading

assets/icons/digital_signature_warning.svg

Lines changed: 1 addition & 1 deletion
Loading

assets/icons/ic-bookmark.svg

Lines changed: 3 additions & 0 deletions
Loading

assets/icons/ic-layer.svg

Lines changed: 5 additions & 0 deletions
Loading

src/components/Bookmark/Bookmark.js

Lines changed: 67 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,27 @@ import React, { useEffect, useRef, useState } from 'react';
22
import { useTranslation } from 'react-i18next';
33
import classNames from 'classnames';
44
import core from 'core';
5+
import PropTypes from 'prop-types';
56

6-
import './Bookmark.scss';
77
import Button from '../Button';
88
import DataElementWrapper from '../DataElementWrapper';
9-
import BookmarkOutlineContextMenuPopup from '../BookmarkOutlineContextMenuPopup';
9+
import MoreOptionsContextMenuPopup from '../MoreOptionsContextMenuPopup';
1010
import Choice from 'components/Choice';
11+
import '../../constants/bookmarksOutlinesShared.scss';
12+
13+
const propTypes = {
14+
text: PropTypes.string.isRequired,
15+
label: PropTypes.string.isRequired,
16+
defaultLabel: PropTypes.string,
17+
pageIndex: PropTypes.number.isRequired,
18+
isAdding: PropTypes.bool,
19+
isMultiSelectionMode: PropTypes.bool,
20+
setSelected: PropTypes.func,
21+
onSave: PropTypes.func.isRequired,
22+
onRemove: PropTypes.func,
23+
onCancel: PropTypes.func,
24+
panelSelector: PropTypes.string,
25+
};
1126

1227
const Bookmark = ({
1328
text,
@@ -20,6 +35,7 @@ const Bookmark = ({
2035
onSave,
2136
onRemove,
2237
onCancel,
38+
panelSelector,
2339
}) => {
2440
const [t] = useTranslation();
2541

@@ -30,19 +46,26 @@ const Bookmark = ({
3046
const [clearSingleClick, setClearSingleClick] = useState(undefined);
3147
const inputRef = useRef();
3248

49+
const isRenameButtonDisabled = () => {
50+
return !bookmarkText || text === bookmarkText;
51+
};
52+
3353
const handleKeyDown = (e) => {
34-
if (e.keyCode === 13) {
35-
onSaveBookmark();
54+
if (e.key === 'Enter') {
55+
e.stopPropagation();
56+
if (isAdding || (isEditing && !isRenameButtonDisabled())) {
57+
onSaveBookmark();
58+
}
3659
}
37-
if (e.keyCode === 27) {
60+
if (e.key === 'Escape') {
3861
onCancelBookmark();
3962
}
40-
}
63+
};
4164

4265
const onSaveBookmark = () => {
4366
setIsEditing(false);
44-
onSave(bookmarkText || t('message.untitled'));
45-
}
67+
onSave(bookmarkText.trim() === '' ? t('message.untitled') : bookmarkText);
68+
};
4669

4770
const onCancelBookmark = () => {
4871
setIsEditing(false);
@@ -51,6 +74,10 @@ const Bookmark = ({
5174
isAdding && onCancel();
5275
};
5376

77+
const setCurrentPage = (pageIndex) => {
78+
core.setCurrentPage(pageIndex + 1);
79+
};
80+
5481
useEffect(() => {
5582
if (bookmarkText !== text) {
5683
setBookmarkText(text);
@@ -74,21 +101,25 @@ const Bookmark = ({
74101
<DataElementWrapper
75102
className={classNames({
76103
'bookmark-outline-single-container': true,
77-
'adding': isAdding,
78-
'editing': isEditing,
104+
'editing': isAdding || isEditing,
79105
'default': isDefault,
80-
'hover': isContextMenuOpen,
81106
})}
82-
onClick={e => {
107+
tabIndex={0}
108+
onKeyDown={(e) => {
109+
if (e.key === 'Enter') {
110+
setCurrentPage(pageIndex);
111+
}
112+
}}
113+
onClick={(e) => {
83114
if (isDefault && e.detail === 1) {
84115
setClearSingleClick(setTimeout(() => {
85-
core.setCurrentPage(pageIndex + 1);
86-
}, 300))
116+
setCurrentPage(pageIndex);
117+
}, 300));
87118
}
88119
}}
89120
onDoubleClick={() => {
90121
if (isDefault) {
91-
clearTimeout(clearSingleClick)
122+
clearTimeout(clearSingleClick);
92123
}
93124
}}
94125
>
@@ -97,8 +128,8 @@ const Bookmark = ({
97128
type="checkbox"
98129
className="bookmark-outline-checkbox"
99130
id={`bookmark-checkbox-${pageIndex + 1}`}
100-
onClick={e => e.stopPropagation()}
101-
onChange={e => setSelected(pageIndex, e.target.checked)}
131+
onClick={(e) => e.stopPropagation()}
132+
onChange={(e) => setSelected(pageIndex, e.target.checked)}
102133
/>
103134
}
104135

@@ -112,7 +143,7 @@ const Bookmark = ({
112143
className="bookmark-outline-more-button"
113144
dataElement={`bookmark-more-button-${pageIndex}`}
114145
img="icon-pencil-line"
115-
onClick={e => {
146+
onClick={(e) => {
116147
e.stopPropagation();
117148
setIsEditing(true);
118149
}}
@@ -122,35 +153,34 @@ const Bookmark = ({
122153
{!isMultiSelectionMode &&
123154
<Button
124155
className="bookmark-outline-more-button"
125-
dataElement={`bookmark-more-button-${pageIndex}`}
156+
dataElement={`bookmark-more-button-${panelSelector}-${pageIndex}`}
126157
img="icon-tool-more"
127-
onClick={e => {
158+
onClick={(e) => {
128159
e.stopPropagation();
129160
setContextMenuOpen(true);
130161
}}
131-
tabIndex={-1}
162+
tabIndex={0 }
132163
/>
133164
}
134165
{isContextMenuOpen && (
135-
<BookmarkOutlineContextMenuPopup
166+
<MoreOptionsContextMenuPopup
136167
type={'bookmark'}
137-
anchorButton={`bookmark-more-button-${pageIndex}`}
168+
anchorButton={`bookmark-more-button-${panelSelector}-${pageIndex}`}
169+
shouldDisplayDeleteButton={true}
138170
onClosePopup={() => setContextMenuOpen(false)}
139-
onRenameClick={e => {
140-
e.stopPropagation();
171+
onRenameClick={() => {
141172
setContextMenuOpen(false);
142173
setIsEditing(true);
143174
}}
144-
onDeleteClick={e => {
145-
e.stopPropagation();
175+
onDeleteClick={() => {
146176
setContextMenuOpen(false);
147177
onRemove(pageIndex);
148178
}}
149179
/>
150180
)}
151181

152182
<div
153-
className="bookmark-outline-text"
183+
className="bookmark-outline-text bookmark-text-input"
154184
onDoubleClick={() => setIsEditing(true)}
155185
>
156186
{text}
@@ -164,12 +194,11 @@ const Bookmark = ({
164194
type="text"
165195
name="bookmark"
166196
ref={inputRef}
167-
className="bookmark-outline-input"
168-
placeholder={t('component.bookmarkTitle')}
197+
className="bookmark-outline-input bookmark-text-input"
169198
aria-label={t('action.name')}
170199
value={bookmarkText}
171200
onKeyDown={handleKeyDown}
172-
onChange={e => setBookmarkText(e.target.value)}
201+
onChange={(e) => setBookmarkText(e.target.value)}
173202
/>
174203

175204
<div className="bookmark-outline-editing-controls">
@@ -182,16 +211,16 @@ const Bookmark = ({
182211
<Button
183212
className="bookmark-outline-save-button"
184213
label={t('action.add')}
185-
isSubmitType={true}
214+
isSubmitType
186215
onClick={onSaveBookmark}
187216
/>
188217
}
189218
{isEditing &&
190219
<Button
191220
className="bookmark-outline-save-button"
192221
label={t('action.save')}
193-
isSubmitType={true}
194-
disabled={bookmarkText === text}
222+
isSubmitType
223+
disabled={isRenameButtonDisabled()}
195224
onClick={onSaveBookmark}
196225
/>
197226
}
@@ -200,7 +229,9 @@ const Bookmark = ({
200229
}
201230
</div>
202231
</DataElementWrapper>
203-
)
204-
}
232+
);
233+
};
234+
235+
Bookmark.propTypes = propTypes;
205236

206237
export default Bookmark;

0 commit comments

Comments
 (0)