Skip to content

Commit

Permalink
feat(Dropdown): add withReadOnlyStyle prop (#1926)
Browse files Browse the repository at this point in the history
  • Loading branch information
talkor authored Feb 5, 2024
1 parent f591551 commit 2ccfdff
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 4 deletions.
2 changes: 2 additions & 0 deletions src/components/Dropdown/Dropdown.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ const Dropdown = forwardRef(
placeholder,
disabled,
readOnly,
withReadOnlyStyle,
onMenuOpen,
onMenuClose,
onFocus,
Expand Down Expand Up @@ -329,6 +330,7 @@ const Dropdown = forwardRef(
isClearable={!readOnly && clearable}
isSearchable={!readOnly && searchable}
readOnly={readOnly}
withReadOnlyStyle={withReadOnlyStyle}
aria-readonly={readOnly}
aria-label={overrideAriaLabel}
aria-details={tooltipContent}
Expand Down
16 changes: 14 additions & 2 deletions src/components/Dropdown/Dropdown.styles.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,16 @@ const readOnlyContainerStyle = readOnly => {
};
};

// TODO: unite backgroundColor style with `readOnlyContainerStyle` in next major [breaking]
const readOnlyStyle = isReadOnly => {
if (!isReadOnly) {
return {};
}
return {
backgroundColor: getCSSVar("allgrey-background-color")
};
};

const getOptionStyle = (provided, { isDisabled, isSelected, isFocused }) => {
delete provided[":active"];
delete provided.width;
Expand Down Expand Up @@ -237,10 +247,11 @@ const menuOpenOpacity = ({ menuIsOpen }) => {
const singleValue =
() =>
(provided, { isDisabled, selectProps }) => {
const { readOnly } = selectProps;
const { readOnly, withReadOnlyStyle } = selectProps;
const readOnlyProps = readOnly
? {
...readOnlyContainerStyle(readOnly),
...readOnlyStyle(withReadOnlyStyle),
cursor: "text"
}
: {};
Expand Down Expand Up @@ -290,13 +301,14 @@ const getCenterContentStyle = rtl => {

const valueContainer =
({ size, rtl }) =>
(provided, { isDisabled }) => ({
(provided, { isDisabled, selectProps: { withReadOnlyStyle, readOnly } }) => ({
...provided,
...getCenterContentStyle(rtl),
...getFont(),
...getColor(),
...getInnerSize(size),
...disabledContainerStyle(isDisabled),
...readOnlyStyle(withReadOnlyStyle && readOnly),
borderRadius: getCSSVar("border-radius-small")
});

Expand Down
8 changes: 6 additions & 2 deletions src/components/Dropdown/__stories__/dropdown.stories.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,16 @@ const dropdownTemplate = props => {
export const Overview = {
render: dropdownTemplate.bind({}),
name: "Overview",

args: {
placeholder: "Placeholder text here",
className: "dropdown-stories-styles_spacing"
},

parameters: {
controls: {
// TODO: remove exclusion when prop is removed in next major
exclude: ["withReadOnlyStyle"]
}
},
play: overviewPlaySuite
};

Expand Down

0 comments on commit 2ccfdff

Please sign in to comment.