Skip to content

Commit

Permalink
Merge branch 'main' into Pagination_display_error
Browse files Browse the repository at this point in the history
  • Loading branch information
riddhybansal authored Jun 27, 2024
2 parents b5b28d1 + 697684e commit 0bdd499
Show file tree
Hide file tree
Showing 9 changed files with 180 additions and 12 deletions.
2 changes: 1 addition & 1 deletion .github/renovate.json5
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
'npm:unpublishSafe',

// https://docs.renovatebot.com/presets-schedule/#scheduledaily
'schedule:weekday',
'schedule:every weekday',
],
vulnerabilityAlerts: {
enabled: true,
Expand Down
20 changes: 13 additions & 7 deletions packages/react/src/components/ComboBox/ComboBox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import React, {
useEffect,
useState,
useRef,
useMemo,
forwardRef,
type ReactNode,
type ComponentType,
Expand Down Expand Up @@ -655,6 +656,15 @@ const ComboBox = forwardRef(
(helperText && !isFluid && helperTextId) ||
undefined;

const menuProps = useMemo(
() =>
getMenuProps({
'aria-label': deprecatedAriaLabel || ariaLabel,
ref: autoAlign ? refs.setFloating : null,
}),
[autoAlign, deprecatedAriaLabel, ariaLabel]
);

return (
<div className={wrapperClasses}>
{titleText && (
Expand All @@ -674,7 +684,7 @@ const ComboBox = forwardRef(
light={light}
size={size}
warn={warn}
ref={refs.setReference}
ref={autoAlign ? refs.setReference : null}
warnText={warnText}
warnTextId={warnTextId}>
<div className={`${prefix}--list-box__field`}>
Expand All @@ -686,7 +696,7 @@ const ComboBox = forwardRef(
aria-haspopup="listbox"
title={textInput?.current?.value}
{...getInputProps({
'aria-controls': isOpen ? undefined : getMenuProps().id,
'aria-controls': isOpen ? undefined : menuProps.id,
placeholder,
ref: { ...mergeRefs(textInput, ref) },
onKeyDown: (
Expand Down Expand Up @@ -785,11 +795,7 @@ const ComboBox = forwardRef(
/>
</div>
{normalizedSlug}
<ListBox.Menu
{...getMenuProps({
'aria-label': deprecatedAriaLabel || ariaLabel,
})}
ref={mergeRefs(getMenuProps().ref, refs.setFloating)}>
<ListBox.Menu {...menuProps}>
{isOpen
? filterItems(items, itemToString, inputValue).map(
(item, index) => {
Expand Down
55 changes: 55 additions & 0 deletions packages/react/src/components/Modal/Modal.stories.js
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,61 @@ export const Playground = ({ numberOfButtons, ...args }) => {
<SelectItem value="us-south" text="US South" />
<SelectItem value="us-east" text="US East" />
</Select>

<Dropdown
autoAlign={true}
id="default"
style={{ margin: '1rem 0' }}
titleText="Dropdown Example of Floating ui"
helperText="This is some helper text"
// initialSelectedItem={items[1]}
label="Option 1"
items={[
{
id: 'option-0',
text: 'Lorem, ipsum dolor sit amet consectetur adipisicing elit.',
},
{
id: 'option-1',
text: 'Option 1',
},
{
id: 'option-2',
text: 'Option 2',
},
{
id: 'option-3',
text: 'Option 3 - a disabled item',
disabled: true,
},
{
id: 'option-4',
text: 'Option 4',
},
{
id: 'option-5',
text: 'Option 5',
},
]}
itemToString={(item) => (item ? item.text : '')}
direction="top"
/>

<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aenean id
accumsan augue. Phasellus consequat augue vitae tellus tincidunt
posuere. Curabitur justo urna, consectetur vel elit iaculis, ultrices
condimentum risus. Nulla facilisi. Etiam venenatis molestie tellus.
Quisque consectetur non risus eu rutrum.{' '}
</p>
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aenean id
accumsan augue. Phasellus consequat augue vitae tellus tincidunt
posuere. Curabitur justo urna, consectetur vel elit iaculis, ultrices
condimentum risus. Nulla facilisi. Etiam venenatis molestie tellus.
Quisque consectetur non risus eu rutrum.{' '}
</p>

{args.hasScrollingContent && (
<>
<p>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -518,8 +518,6 @@ const FilterableMultiSelect = React.forwardRef(function FilterableMultiSelect<
return changes;
case InputBlur:
case InputKeyDownEscape:
setInputFocused(false);
setInputValue('');
setIsOpen(false);
return changes;
case FunctionToggleMenu:
Expand Down Expand Up @@ -714,6 +712,10 @@ const FilterableMultiSelect = React.forwardRef(function FilterableMultiSelect<
}
},
onFocus: () => setInputFocused(true),
onBlur: () => {
!isOpen && setInputFocused(false);
setInputValue('');
},
})
);
const menuProps = getMenuProps({}, { suppressRefError: true });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,20 @@ describe('FilterableMultiSelect', () => {
expect(screen.getByPlaceholderText('test')).toHaveDisplayValue(3);
});

it('should clear input value when clicking on cross button', async () => {
render(<FilterableMultiSelect {...mockProps} placeholder="test" />);
await openMenu();

await userEvent.type(screen.getByPlaceholderText('test'), '3');

const clearButton = screen.getByRole('button', {
name: 'Clear selected item',
});
await userEvent.click(clearButton);

expect(screen.getByPlaceholderText('test')).toHaveDisplayValue('');
});

it('should respect slug prop', async () => {
const { container } = render(
<FilterableMultiSelect {...mockProps} slug={<Slug />} />
Expand Down
26 changes: 25 additions & 1 deletion packages/react/src/components/OverflowMenu/OverflowMenu-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import OverflowMenu from './OverflowMenu';
import OverflowMenuItem from '../OverflowMenuItem';
import { Filter } from '@carbon/icons-react';
import userEvent from '@testing-library/user-event';
import { render, screen } from '@testing-library/react';
import { render, screen, fireEvent } from '@testing-library/react';

describe('OverflowMenu', () => {
describe('Renders as expected', () => {
Expand Down Expand Up @@ -171,5 +171,29 @@ describe('OverflowMenu', () => {
'true'
);
});

it('should call onClick handler only once per click', async () => {
const handleClick = jest.fn();

render(
<OverflowMenu
open
aria-label="Overflow menu"
className="extra-class"
onClick={handleClick}>
<OverflowMenuItem className="test-child" itemText="one" />
<OverflowMenuItem className="test-child" itemText="two" />
</OverflowMenu>
);

// Find the OverflowMenu button
const button = screen.getByRole('button');

// Click the OverflowMenu button
await userEvent.click(button);

// Check that the click handler was called only once
expect(handleClick).toHaveBeenCalledTimes(1);
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -439,7 +439,6 @@ class OverflowMenu extends React.Component<
handleClick = (evt) => {
const { onClick = noopFn } = this.props;
this.setState({ click: true });
evt.stopPropagation();
if (!this._menuBody || !this._menuBody.contains(evt.target)) {
this.setState({ open: !this.state.open });
onClick(evt);
Expand Down
63 changes: 63 additions & 0 deletions packages/react/src/components/Popover/Popover.stories.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ import { default as Checkbox } from '../Checkbox';
import mdx from './Popover.mdx';
import { Settings } from '@carbon/icons-react';
import { keys, match } from '../../internal/keyboard';
import OverflowMenu from '../OverflowMenu/OverflowMenu';
import OverflowMenuItem from '../OverflowMenuItem';

const prefix = 'cds';

Expand Down Expand Up @@ -267,6 +269,67 @@ export const ExperimentalAutoAlign = () => {
</div>
);
};
export const Test = () => {
const [open, setOpen] = useState();
const align = document?.dir === 'rtl' ? 'bottom-right' : 'bottom-left';
const alignTwo = document?.dir === 'rtl' ? 'bottom-left' : 'bottom-right';
return (
<div style={{ display: 'flex', gap: '8rem' }}>
<OverflowMenu
flipped={document?.dir === 'rtl'}
aria-label="overflow-menu">
<OverflowMenuItem itemText="Stop app" />
<OverflowMenuItem itemText="Restart app" />
<OverflowMenuItem itemText="Rename app" />
<OverflowMenuItem itemText="Clone and move app" disabled requireTitle />
<OverflowMenuItem itemText="Edit routes and access" requireTitle />
<OverflowMenuItem hasDivider isDelete itemText="Delete app" />
</OverflowMenu>

<Popover
align={align}
open={open}
onKeyDown={(evt) => {
if (match(evt, keys.Escape)) {
setOpen(false);
}
}}
isTabTip
onRequestClose={() => setOpen(false)}>
<button
aria-label="Settings"
type="button"
aria-expanded={open}
onClick={() => {
setOpen(!open);
}}>
<Settings />
</button>
<PopoverContent className="p-3">
<RadioButtonGroup
style={{ alignItems: 'flex-start', flexDirection: 'column' }}
legendText="Row height"
name="radio-button-group"
defaultSelected="small">
<RadioButton labelText="Small" value="small" id="radio-small" />
<RadioButton labelText="Large" value="large" id="radio-large" />
</RadioButtonGroup>
<hr />
<fieldset className={`cds--fieldset`}>
<legend className={`cds--label`}>Edit columns</legend>
<Checkbox defaultChecked labelText="Name" id="checkbox-label-1" />
<Checkbox defaultChecked labelText="Type" id="checkbox-label-2" />
<Checkbox
defaultChecked
labelText="Location"
id="checkbox-label-3"
/>
</fieldset>
</PopoverContent>
</Popover>
</div>
);
};

export const TabTipExperimentalAutoAlign = () => {
const [open, setOpen] = useState(true);
Expand Down
5 changes: 5 additions & 0 deletions packages/styles/scss/components/modal/_modal.scss
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,11 @@
linear-gradient(to top, $layer 0, 2px, transparent 2px);
}

//removing mask image in case we have dropdown in modal
.#{$prefix}--modal-scroll-content:has(.#{$prefix}--dropdown--autoalign) {
mask-image: none;
}

// Required so overflow-indicator disappears at end of content
.#{$prefix}--modal-scroll-content > *:last-child {
margin-block-end: $spacing-06;
Expand Down

0 comments on commit 0bdd499

Please sign in to comment.