Skip to content

Commit

Permalink
fix: sonar cloud ternary operation related issues
Browse files Browse the repository at this point in the history
  • Loading branch information
pphminions committed Oct 9, 2022
1 parent 0306682 commit 3fb0e2f
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 12 deletions.
4 changes: 3 additions & 1 deletion src/components/Checkbox/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,15 @@ const Checkbox = ({
onKeyDown?.(event);
};

const ariaChecked = checked ? 'true' : 'false';

return (
<div
{...rest}
data-testid="checkbox"
role="checkbox"
aria-disabled={disabled ? 'true' : undefined}
aria-checked={checked === 'partial' ? 'mixed' : checked ? 'true' : 'false'}
aria-checked={checked === 'partial' ? 'mixed' : ariaChecked}
className={classnames(
'aui--checkbox',
{
Expand Down
4 changes: 3 additions & 1 deletion src/components/Radio/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ const Radio = ({
onChange?.(value);
};

const tabIndex = checked || groupValue?.length === 0 ? 0 : -1;

return (
<div
{...rest}
Expand All @@ -58,7 +60,7 @@ const Radio = ({
className
)}
data-aui-value={value}
tabIndex={!groupValue ? 0 : checked || groupValue.length === 0 ? 0 : -1}
tabIndex={!groupValue ? 0 : tabIndex}
onKeyDown={(event) => {
if (SELECTION_KEYS.includes(event.key) && !checked) {
event.preventDefault();
Expand Down
7 changes: 2 additions & 5 deletions src/components/Search/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ const Search = React.forwardRef(
const closeIcon = icons.close ? icons.close : <div data-testid="close-icon" className="cancel-icon" />;
const loaderIcon = icons.loader ? icons.loader : <Spinner size="small" />;
const isValueEmpty = _.isEmpty(value) && _.isEmpty(inputValue);
const searchIconValue = isValueEmpty ? {} : { onClick: onInputClear };

return (
<div
Expand Down Expand Up @@ -120,11 +121,7 @@ const Search = React.forwardRef(
/>
</>
) : (
<span
data-testid="search-icon-wrapper"
className="aui--search-component-icon"
{...(isValueEmpty ? {} : { onClick: onInputClear })}
>
<span data-testid="search-icon-wrapper" className="aui--search-component-icon" {...searchIconValue}>
{isValueEmpty ? searchIcon : closeIcon}
</span>
)}
Expand Down
9 changes: 4 additions & 5 deletions src/components/SearchableCheckList/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,12 @@ const SearchableCheckList = ({
itemsToRender = _.union(itemsToRender, _.slice(unSelectedItems, 0, displayCount - itemsToRender.length));
}

const mainCheckBoxState =
selectedItemsKeys.length === 0 ? false : selectedItemsKeys.length === items.length ? true : 'partial';
const selectedItemsKeysLength = selectedItemsKeys.length === items.length ? true : 'partial';
const mainCheckBoxState = selectedItemsKeys.length === 0 ? false : selectedItemsKeysLength;

const { singularLabel, pluralLabel } = context;
const remainingItemsCount = items.length - itemsToRender.length;
const footerLabel = remainingItemsCount > 1 ? pluralLabel : singularLabel;

return (
<div className="aui--searchable-checklist">
Expand Down Expand Up @@ -100,9 +101,7 @@ const SearchableCheckList = ({
<div className="footer" data-testid="footer-section">
{!_.isEmpty(footerText)
? footerText
: `${remainingItemsCount.toLocaleString()} more ${_.toLower(
remainingItemsCount > 1 ? pluralLabel : singularLabel
)}`}
: `${remainingItemsCount.toLocaleString()} more ${_.toLower(footerLabel)}`}
</div>
)}
</div>
Expand Down

0 comments on commit 3fb0e2f

Please sign in to comment.