Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(@clayui/form): LPD-36696 DualListBox adds children and don't disable left right buttons if no items are selected #5874

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 5 additions & 6 deletions packages/clay-form/src/DualListBox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ const ClayDualListBox = ({
transferLTR: 'Transfer Item Left to Right',
transferRTL: 'Transfer Item Right to Left',
},
children,
className,
disabled,
disableLTR,
Expand Down Expand Up @@ -166,9 +167,7 @@ const ClayDualListBox = ({
aria-label={ariaLabels.transferLTR}
className="transfer-button-ltr"
data-testid="ltr"
disabled={
leftSelected.length === 0 || disableLTR || disabled
}
disabled={disableLTR || disabled}
displayType="secondary"
onClick={() => {
const [arrayLeft, arrayRight] = swapArrayItems(
Expand All @@ -187,9 +186,7 @@ const ClayDualListBox = ({
aria-label={ariaLabels.transferRTL}
className="transfer-button-rtl"
data-testid="rtl"
disabled={
rightSelected.length === 0 || disableRTL || disabled
}
disabled={disableRTL || disabled}
displayType="secondary"
onClick={() => {
const [arrayRight, arrayLeft] = swapArrayItems(
Expand Down Expand Up @@ -222,6 +219,8 @@ const ClayDualListBox = ({
value={rightSelected}
/>
</div>

{children}
</div>
);
};
Expand Down
33 changes: 29 additions & 4 deletions packages/clay-form/stories/DualListBox.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
* SPDX-License-Identifier: BSD-3-Clause
*/

import classnames from 'classnames';
import React, {useState} from 'react';

import {ClayDualListBox} from '../src';
import ClayForm, {ClayDualListBox} from '../src';

export default {
argTypes: {
Expand Down Expand Up @@ -59,19 +60,27 @@ const moveBoxesOptions = [

export const Default = (args: any) => {
const [items, setItems] = useState(moveBoxesOptions);

const [leftSelected, setLeftSelected] = useState<Array<string>>([]);
const [rightSelected, setRightSelected] = useState<Array<string>>([]);

const [firstSelectBoxItems, secondSelectBoxItems] = items;

const isLeftError =
rightSelected.length + firstSelectBoxItems.length > args.leftMaxItems;
const isRightError =
leftSelected.length + secondSelectBoxItems.length > args.rightMaxItems;

return (
<ClayDualListBox
disableLTR={
args.disableLTR ||
isRightError ||
secondSelectBoxItems.length >= args.rightMaxItems
}
disableRTL={
args.disableRTL ||
isLeftError ||
firstSelectBoxItems.length >= args.leftMaxItems
}
disabled={args.disabled}
Expand All @@ -82,15 +91,31 @@ export const Default = (args: any) => {
onSelectChange: setLeftSelected,
selected: leftSelected,
}}
onItemsChange={setItems}
onItemsChange={(event) => {
setItems(event);
setLeftSelected([]);
setRightSelected([]);
}}
right={{
id: 'rightSelectBox',
label: 'In Use',
onSelectChange: setRightSelected,
selected: rightSelected,
}}
size={8}
/>
>
<ClayForm.FeedbackGroup
className={classnames('d-none', 'has-error', {
'd-block': isLeftError || isRightError,
})}
>
<ClayForm.FeedbackItem>
The maximum number of items for{' '}
{isLeftError ? 'Available' : 'In Use'} is{' '}
{args.leftMaxItems}
</ClayForm.FeedbackItem>
</ClayForm.FeedbackGroup>
</ClayDualListBox>
);
};

Expand All @@ -99,5 +124,5 @@ Default.args = {
disableRTL: false,
disabled: false,
leftMaxItems: 5,
rightMaxItems: 3,
rightMaxItems: 5,
};
Loading