Skip to content

Commit f90c9eb

Browse files
key callbacks: Allow stopPropagation when other
Catch alls should not trap all key events
1 parent d12ce75 commit f90c9eb

File tree

3 files changed

+14
-13
lines changed

3 files changed

+14
-13
lines changed

components/combobox/combobox.jsx

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -529,8 +529,15 @@ class Combobox extends React.Component {
529529
};
530530

531531
if (this.props.variant === 'readonly') {
532-
callbacks[KEYS.TAB] = { callback: this.handleKeyDownTab };
533-
callbacks.other = { callback: this.handleKeyDownOther };
532+
if (this.props.selection.length > 2) {
533+
callbacks[KEYS.TAB] = { callback: this.handleKeyDownTab };
534+
} else {
535+
callbacks[KEYS.TAB] = undefined;
536+
}
537+
callbacks.other = {
538+
callback: this.handleKeyDownOther,
539+
stopPropagation: false,
540+
};
534541
}
535542

536543
// Helper function that takes an object literal of callbacks that are triggered with a key event

components/pill-container/private/selected-listbox.jsx

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -180,14 +180,7 @@ const SelectedListBox = (props) =>
180180
aria-label={props.assistiveText.selectedListboxLabel}
181181
>
182182
{props.selection.map((option, renderIndex) => {
183-
// Makes first pill in DOM snapshots have aria-selected=true on first render
184-
const setActiveBasedOnstateFromParent =
185-
renderIndex === props.activeOptionIndex &&
186-
isEqual(option, props.activeOption);
187-
const listboxRenderedForFirstTime =
188-
props.activeOptionIndex === -1 && renderIndex === 0;
189-
const active =
190-
setActiveBasedOnstateFromParent || listboxRenderedForFirstTime;
183+
const hasTabIndex = renderIndex === props.activeOptionIndex;
191184
const icon = getIcon(option);
192185
const avatar = !icon ? getAvatar(option) : null;
193186

@@ -198,7 +191,7 @@ const SelectedListBox = (props) =>
198191
key={`${props.id}-list-item-${option.id}`}
199192
>
200193
<Pill
201-
active={active}
194+
active={hasTabIndex && props.listboxHasFocus}
202195
assistiveText={{
203196
remove: props.assistiveText.removePill,
204197
}}
@@ -234,7 +227,7 @@ const SelectedListBox = (props) =>
234227
removeTitle: props.labels.removePillTitle,
235228
}}
236229
requestFocus={props.listboxHasFocus}
237-
tabIndex={active ? 0 : -1}
230+
tabIndex={hasTabIndex ? 0 : -1}
238231
/>
239232
</li>
240233
);

utilities/key-callbacks.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ const mapKeyEventCallbacks = (
2626
}
2727
callbacks[event.keyCode].callback(event, callbacks[event.keyCode].data);
2828
} else if (event.keyCode && callbacks.other) {
29-
if (stopPropagation) {
29+
// You will likely NOT want to stop propagation of all key presses!
30+
if (callbacks.other.stopPropagation) {
3031
EventUtil.trapEvent(event);
3132
}
3233
callbacks.other.callback(event, callbacks.other.data);

0 commit comments

Comments
 (0)