Skip to content

Commit

Permalink
refactor: code refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
PKulkoRaccoonGang committed Apr 25, 2023
1 parent 08a034a commit d3d54d4
Show file tree
Hide file tree
Showing 9 changed files with 22 additions and 10 deletions.
2 changes: 1 addition & 1 deletion src/Menu/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ A ``MenuItem`` is its own distinct component that is used by any kind of menu ov
<MenuItem iconBefore={Check}>A Menu Item With an Icon Before</MenuItem>
<MenuItem iconAfter={Check}>A Menu Item With an Icon After </MenuItem>
<MenuItem disabled>A Disabled Menu Item</MenuItem>
<MenuItem as={Hyperlink} href="https://en.wikipedia.org/wiki/Hyperlink">A Link Menu Item</MenuItem>
<MenuItem as="a" href="https://en.wikipedia.org/wiki/Hyperlink">A Link Menu Item</MenuItem>
<MenuItem as={Button} variant="tertiary" size="inline">A Button Menu Item</MenuItem>
<MenuItem as={Form.Checkbox}>A Checkbox Menu Item</MenuItem>
</Menu>
Expand Down
3 changes: 1 addition & 2 deletions src/Menu/SelectMenu.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { mount } from 'enzyme';
import renderer from 'react-test-renderer';
import { Add, Check } from '../../icons';
import { MenuItem, SelectMenu } from '..';
import Hyperlink from '../Hyperlink';
import Button from '../Button';

const app = document.createElement('div');
Expand All @@ -15,7 +14,7 @@ const selectMenu = mount(
<MenuItem iconBefore={Add}>A Menu Item With an Icon Before</MenuItem>
<MenuItem iconAfter={Check}>A Menu Item With an Icon After </MenuItem>
<MenuItem disabled>A Disabled Menu Item</MenuItem>
<MenuItem as={Hyperlink} href="https://en.wikipedia.org/wiki/Hyperlink">A Link Menu Item</MenuItem>
<MenuItem as="a" href="https://en.wikipedia.org/wiki/Hyperlink">A Link Menu Item</MenuItem>
<MenuItem>Falstaff</MenuItem>
<MenuItem>Scipio</MenuItem>
<MenuItem>Faustus</MenuItem>
Expand Down
4 changes: 2 additions & 2 deletions src/Menu/select-menu.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,14 @@ The ``Modal`` brings focus to the first menu element upon the click of the trigg
<MenuItem iconBefore={Add}>A Menu Item With an Icon Before</MenuItem>
<MenuItem iconAfter={Check}>A Menu Item With an Icon After </MenuItem>
<MenuItem disabled>A Disabled Menu Item</MenuItem>
<MenuItem as={Hyperlink} href="https://en.wikipedia.org/wiki/Hyperlink">A Link Menu Item</MenuItem>
<MenuItem as="a" href="https://en.wikipedia.org/wiki/Hyperlink">A Link Menu Item</MenuItem>
</SelectMenu>
```

#### Linked variant

```jsx live
<SelectMenu isLink={true} defaultMessage="Choose Your New Best Friend">
<SelectMenu defaultMessage="Choose Your New Best Friend">
<MenuItem>Falstaff</MenuItem>
<MenuItem>Scipio</MenuItem>
<MenuItem defaultSelected>Faustus</MenuItem>
Expand Down
5 changes: 3 additions & 2 deletions src/Modal/PopperElement.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ function PopperElement({
const {
styles,
attributes,
} = usePopper(target, popperElement, popperOptions);
} = usePopper(target?.current, popperElement, popperOptions);

if (!target) {
return null;
Expand All @@ -30,7 +30,8 @@ PopperElement.defaultProps = {
PopperElement.propTypes = {
children: PropTypes.node,
target: PropTypes.shape({
current: PropTypes.node,
// eslint-disable-next-line react/forbid-prop-types
current: PropTypes.object,
}),
strategy: PropTypes.oneOf(['absolute', 'fixed']),
placement: PropTypes.oneOf([
Expand Down
2 changes: 1 addition & 1 deletion src/Modal/PopperElement.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ describe('<PopperElement />', () => {
</PopperElement>
));
const popperEl = wrapper.find('[data-test="someValue"]');
expect(usePopper).toHaveBeenCalledWith(targetRef, null, defaultPopperOptions);
expect(usePopper).toHaveBeenCalledWith(<div />, null, defaultPopperOptions);
expect(popperEl.length).toBe(1);
expect(popperEl.props().style.someProperty).toBe('someValue');
});
Expand Down
2 changes: 1 addition & 1 deletion src/ProductTour/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const ProductTour = React.forwardRef(({ tours }, ref) => {
advanceButtonText: tourAdvanceButtonText, dismissButtonText: tourDismissButtonText,
endButtonText: tourEndButtonText,
} = tourValue || {};
const [currentCheckpointData, setCurrentCheckpointData] = useState([]);
const [currentCheckpointData, setCurrentCheckpointData] = useState(null);
const [index, setIndex] = useState(0);
const [isTourEnabled, setIsTourEnabled] = useState(false);
const [prunedCheckpoints, setPrunedCheckpoints] = useState([]);
Expand Down
2 changes: 1 addition & 1 deletion src/SelectableBox/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ const SelectableBox = React.forwardRef(({
tabIndex: -1,
onChange: () => {},
...(type === 'checkbox' ? { ...props, isIndeterminate } : { ...props }),
}, null);
}, false);

useEffect(() => {
if (onClick && inputRef.current) {
Expand Down
6 changes: 6 additions & 0 deletions src/SelectableBox/tests/SelectableBox.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,17 @@ describe('<SelectableBox />', () => {
expect(boxWrapper.find(Form.Checkbox).length).toBeGreaterThan(0);
});
it('renders with radio input type if neither checkbox nor radio is passed', () => {
// Hiding the `console.error` is intentional because an invalid `type` prop
// with `wrongType` specified for `ForwardRef` expects one of the ['radio','flag'] parameters.
// eslint-disable-next-line no-console
console.error = jest.fn();
const wrapper = mount(
<SelectableBox type="wrongType">SelectableBox</SelectableBox>,
);
const selectableBox = wrapper.find('input');
expect(selectableBox.prop('type')).toEqual(radioType);
// eslint-disable-next-line no-console
console.error.mockRestore();
});
it('renders with checkbox input type', () => {
const wrapper = mount(<SelectableCheckbox />);
Expand Down
6 changes: 6 additions & 0 deletions src/SelectableBox/tests/SelectableBoxSet.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,17 @@ describe('<SelectableBox.Set />', () => {
expect(selectableBoxSet.length).toEqual(1);
});
it('renders with radio type if neither checkbox nor radio is passed', () => {
// Hiding the `console.error` is intentional because an invalid `type` prop
// with type `text` specified for `ForwardRef` expects one of the ['radio','checkbox'] parameters.
// eslint-disable-next-line no-console
console.error = jest.fn();
const wrapper = mount(
<SelectableCheckboxSet type="text">SelectableCheckboxSet</SelectableCheckboxSet>,
);
const selectableBoxSet = wrapper.find(Form.RadioSet);
expect(selectableBoxSet.length).toEqual(1);
// eslint-disable-next-line no-console
console.error.mockRestore();
});
it('renders with radio type', () => {
const wrapper = mount(
Expand Down

0 comments on commit d3d54d4

Please sign in to comment.