Skip to content

Commit

Permalink
Merge pull request #5863 from pat270/LPD-34319
Browse files Browse the repository at this point in the history
fix(@clayui/form): LPD-34319 adds disabled to Dual Listbox
  • Loading branch information
matuzalemsteles authored Aug 21, 2024
2 parents 12a89bb + bd67e2a commit 71c1453
Show file tree
Hide file tree
Showing 7 changed files with 54 additions and 8 deletions.
7 changes: 7 additions & 0 deletions packages/clay-css/src/scss/atlas/variables/_forms.scss
Original file line number Diff line number Diff line change
Expand Up @@ -448,6 +448,13 @@ $input-select-size: map-deep-merge(
),
),
),
disabled: (
option: (
hover: (
background-image: none,
),
),
),
option: (
padding: 0.4375rem 0.5rem,
hover: (
Expand Down
9 changes: 6 additions & 3 deletions packages/clay-css/src/scss/cadmin/components/_forms.scss
Original file line number Diff line number Diff line change
Expand Up @@ -131,10 +131,13 @@ fieldset[disabled] label {

// This adds disabled styles to div.form-control inside a disabled fielset.

fieldset[disabled] .form-control {
$disabled: setter(map-get($cadmin-input, disabled), ());
fieldset[disabled] {
select.form-control[multiple],
.form-control {
$disabled: setter(map-get($cadmin-input, disabled), ());

@include clay-css($disabled);
@include clay-css($disabled);
}
}

// Readonly controls as plain text
Expand Down
7 changes: 7 additions & 0 deletions packages/clay-css/src/scss/cadmin/variables/_forms.scss
Original file line number Diff line number Diff line change
Expand Up @@ -1326,6 +1326,13 @@ $cadmin-input-select-size: map-deep-merge(
),
),
),
disabled: (
option: (
hover: (
background-image: none,
),
),
),
option: (
padding: 7px 8px,
checked: (
Expand Down
7 changes: 5 additions & 2 deletions packages/clay-css/src/scss/components/_forms.scss
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,11 @@ fieldset[disabled] label {

// This adds disabled styles to div.form-control inside a disabled fielset.

fieldset[disabled] .form-control {
@include clay-css(map-get($input, disabled));
fieldset[disabled] {
select.form-control[multiple],
.form-control {
@include clay-css(map-get($input, disabled));
}
}

// Readonly controls as plain text
Expand Down
16 changes: 14 additions & 2 deletions packages/clay-form/src/DualListBox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,11 @@ interface IProps extends React.HTMLAttributes<HTMLDivElement> {
transferRTL: string;
};

/**
* Disables the component.
*/
disabled?: boolean;

/**
* Disables the button responsible for moving items from right to left box.
*/
Expand Down Expand Up @@ -107,6 +112,7 @@ const ClayDualListBox = ({
transferRTL: 'Transfer Item Right to Left',
},
className,
disabled,
disableLTR,
disableRTL,
items = [[], []],
Expand Down Expand Up @@ -142,6 +148,7 @@ const ClayDualListBox = ({
<div className="clay-dual-listbox">
<ClaySelectBox
className="clay-dual-listbox-item clay-dual-listbox-item-expand listbox-left"
disabled={disabled}
id={left.id}
items={leftItems!}
label={left.label}
Expand All @@ -159,7 +166,9 @@ const ClayDualListBox = ({
aria-label={ariaLabels.transferLTR}
className="transfer-button-ltr"
data-testid="ltr"
disabled={leftSelected.length === 0 || disableLTR}
disabled={
leftSelected.length === 0 || disableLTR || disabled
}
displayType="secondary"
onClick={() => {
const [arrayLeft, arrayRight] = swapArrayItems(
Expand All @@ -178,7 +187,9 @@ const ClayDualListBox = ({
aria-label={ariaLabels.transferRTL}
className="transfer-button-rtl"
data-testid="rtl"
disabled={rightSelected.length === 0 || disableRTL}
disabled={
rightSelected.length === 0 || disableRTL || disabled
}
displayType="secondary"
onClick={() => {
const [arrayRight, arrayLeft] = swapArrayItems(
Expand All @@ -196,6 +207,7 @@ const ClayDualListBox = ({

<ClaySelectBox
className="clay-dual-listbox-item clay-dual-listbox-item-expand listbox-right"
disabled={disabled}
id={right.id}
items={rightItems!}
label={right.label}
Expand Down
14 changes: 13 additions & 1 deletion packages/clay-form/src/SelectBox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,11 @@ interface IProps extends React.HTMLAttributes<HTMLSelectElement> {
*/
buttonAlignment?: 'center' | 'end';

/**
* Disables the component.
*/
disabled?: boolean;

/**
* Items to be displayed in the Select Box.
*/
Expand Down Expand Up @@ -137,6 +142,7 @@ const ClaySelectBox = ({
},
buttonAlignment = 'end',
className,
disabled,
id,
items,
label,
Expand Down Expand Up @@ -165,7 +171,12 @@ const ClaySelectBox = ({
return (
<div className={classNames(className, 'form-group')}>
{label && (
<label className="reorder-label" htmlFor={id}>
<label
className={classNames('reorder-label', {
disabled,
})}
htmlFor={id}
>
{label}
</label>
)}
Expand All @@ -178,6 +189,7 @@ const ClaySelectBox = ({
<select
{...otherProps}
className="form-control form-control-inset"
disabled={disabled}
id={id}
multiple={multiple}
onChange={(event) => {
Expand Down
2 changes: 2 additions & 0 deletions packages/clay-form/stories/DualListBox.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ export const Default = (args: any) => {
args.disableRTL ||
firstSelectBoxItems.length >= args.leftMaxItems
}
disabled={args.disabled}
items={items}
left={{
id: 'leftSelectBox',
Expand All @@ -96,6 +97,7 @@ export const Default = (args: any) => {
Default.args = {
disableLTR: false,
disableRTL: false,
disabled: false,
leftMaxItems: 5,
rightMaxItems: 3,
};

0 comments on commit 71c1453

Please sign in to comment.