diff --git a/packages/react/__tests__/__snapshots__/PublicAPI-test.js.snap b/packages/react/__tests__/__snapshots__/PublicAPI-test.js.snap
index 5a27a5bc8cb4..f30ef4876bdc 100644
--- a/packages/react/__tests__/__snapshots__/PublicAPI-test.js.snap
+++ b/packages/react/__tests__/__snapshots__/PublicAPI-test.js.snap
@@ -4929,6 +4929,9 @@ Map {
"open": Object {
"type": "bool",
},
+ "readOnly": Object {
+ "type": "bool",
+ },
"selectedItems": Object {
"type": "array",
},
diff --git a/packages/react/src/components/ListBox/ListBoxSelection.js b/packages/react/src/components/ListBox/ListBoxSelection.js
index d05822d80055..da6f19a3e12f 100644
--- a/packages/react/src/components/ListBox/ListBoxSelection.js
+++ b/packages/react/src/components/ListBox/ListBoxSelection.js
@@ -23,6 +23,7 @@ function ListBoxSelection({
translateWithId: t,
disabled,
onClearSelection,
+ readOnly,
}) {
const prefix = usePrefix();
const className = cx(`${prefix}--list-box__selection`, {
@@ -31,7 +32,7 @@ function ListBoxSelection({
});
const handleOnClick = (event) => {
event.stopPropagation();
- if (disabled) {
+ if (disabled || readOnly) {
return;
}
clearSelection(event);
@@ -41,7 +42,7 @@ function ListBoxSelection({
};
const handleOnKeyDown = (event) => {
event.stopPropagation();
- if (disabled) {
+ if (disabled || readOnly) {
return;
}
@@ -75,7 +76,8 @@ function ListBoxSelection({
onKeyDown={handleOnKeyDown}
disabled={disabled}
aria-label={t('clear.all')}
- title={description}>
+ title={description}
+ aria-disabled={readOnly ? true : undefined}>
@@ -134,6 +136,11 @@ ListBoxSelection.propTypes = {
*/
onKeyDown: PropTypes.func,
+ /**
+ * Whether or not the Dropdown is readonly
+ */
+ readOnly: PropTypes.bool,
+
/**
* Specify an optional `selectionCount` value that will be used to determine
* whether the selection should display a badge or a single clear icon.
diff --git a/packages/react/src/components/MultiSelect/MultiSelect.js b/packages/react/src/components/MultiSelect/MultiSelect.js
index ae686e941029..b0d1aa5d2d9e 100644
--- a/packages/react/src/components/MultiSelect/MultiSelect.js
+++ b/packages/react/src/components/MultiSelect/MultiSelect.js
@@ -70,6 +70,7 @@ const MultiSelect = React.forwardRef(function MultiSelect(
onMenuChange,
direction,
selectedItems: selected,
+ readOnly,
},
ref
) {
@@ -169,6 +170,7 @@ const MultiSelect = React.forwardRef(function MultiSelect(
[`${prefix}--multi-select--selected`]:
selectedItems && selectedItems.length > 0,
[`${prefix}--list-box--up`]: direction === 'top',
+ [`${prefix}--multi-select--readonly`]: readOnly,
}
);
@@ -234,6 +236,24 @@ const MultiSelect = React.forwardRef(function MultiSelect(
: setIsFocused(evt.type === 'focus' ? true : false);
};
+ const readOnlyEventHandlers = readOnly
+ ? {
+ onClick: (evt) => {
+ // NOTE: does not prevent click
+ evt.preventDefault();
+ // focus on the element as per readonly input behavior
+ evt.target.focus();
+ },
+ onKeyDown: (evt) => {
+ const selectAccessKeys = ['ArrowDown', 'ArrowUp', ' ', 'Enter'];
+ // This prevents the select from opening for the above keys
+ if (selectAccessKeys.includes(evt.key)) {
+ evt.preventDefault();
+ }
+ },
+ }
+ : {};
+
return (