Skip to content

Commit

Permalink
Merge branch 'master' into FE-4332-simple-select-mdx-test-story-issue
Browse files Browse the repository at this point in the history
  • Loading branch information
Michał Maciorowski authored Sep 24, 2021
2 parents f6e8fc5 + df52da5 commit 887fc58
Show file tree
Hide file tree
Showing 77 changed files with 1,072 additions and 624 deletions.
26 changes: 26 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,29 @@
### [90.0.1](https://github.com/Sage/carbon/compare/v90.0.0...v90.0.1) (2021-09-24)


### Bug Fixes

* **vertical-divider:** change tint type to number ([bbe5556](https://github.com/Sage/carbon/commit/bbe55562f0b664867934f56fb344d413c84a2621)), closes [#4422](https://github.com/Sage/carbon/issues/4422)

## [90.0.0](https://github.com/Sage/carbon/compare/v89.3.0...v90.0.0) (2021-09-24)


### ⚠ BREAKING CHANGES

* **inputs:** Props not declared in propTypes (including className) are no longer
being spread on the root element in following components:
ButtonToggleGroup, Checkbox, Date, Decimal,
GroupedCharacter, Number, RadioButton, Select, MultiSelect,
FilterableSelect, Switch, Textarea, Textbox.

Furthermore in all these components apart from the ButtonToggleGroup
all not declared props will be passed to the underlying HTML input
element

### Code Refactoring

* **inputs:** change the way props are spread internally ([1cc93ec](https://github.com/Sage/carbon/commit/1cc93ec3e81acf5f8c44834d327587daaca46ae5))

## [89.3.0](https://github.com/Sage/carbon/compare/v89.2.0...v89.3.0) (2021-09-23)


Expand Down
2 changes: 1 addition & 1 deletion cypress/locators/switch/locators.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// component preview locators
const SWITCH_DATA_COMPONENT = '[data-component="Switch"]';
const SWITCH_DATA_COMPONENT = '[data-component="switch"]';

export default SWITCH_DATA_COMPONENT;
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "carbon-react",
"version": "89.3.0",
"version": "90.0.1",
"description": "A library of reusable React components for easily building user interfaces.",
"engineStrict": true,
"engines": {
Expand Down
31 changes: 15 additions & 16 deletions src/__internal__/checkable-input/checkable-input.component.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,18 @@ import HiddenCheckableInput from "./hidden-checkable-input.component";
import guid from "../../utils/helpers/guid";

const CheckableInput = ({
autoFocus,
checked,
children,
disabled,
error,
fieldHelp,
fieldHelpInline,
info,
inputId,
id: inputId,
inputRef,
inputType,
inputValue,
type,
value,
inputWidth,
label,
labelAlign,
Expand All @@ -35,14 +36,13 @@ const CheckableInput = ({
onFocus,
required,
reverse,
tabindex,
validationOnLabel,
warning,
...props
}) => {
const { current: id } = useRef(inputId || guid());
const labelId = `${id} label`;
const helpId = `${id} help`;
const isRadio = inputType === "radio";
const isRadio = type === "radio";

const formFieldProps = {
disabled,
Expand All @@ -56,7 +56,6 @@ const CheckableInput = ({
labelAlign,
labelHelp,
labelHelpIcon: "info",
labelId,
labelInline,
labelSpacing,
name: id,
Expand All @@ -69,20 +68,20 @@ const CheckableInput = ({
};

const inputProps = {
autoFocus,
checked,
disabled,
helpId,
id,
inputRef,
inputType,
inputValue,
labelId,
type,
value,
name,
onBlur,
onChange,
onFocus,
required,
tabindex,
...props,
};

return (
Expand All @@ -107,6 +106,8 @@ const CheckableInput = ({
};

CheckableInput.propTypes = {
/** If true the Component will be focused when page load */
autoFocus: PropTypes.bool,
/** Set the value of the CheckableInput */
checked: PropTypes.bool,
/** Used to set the visible aspect of the input (i.e. the checkbox sprite, input slider etc) */
Expand All @@ -130,11 +131,11 @@ CheckableInput.propTypes = {
/** Displays fieldHelp inline with the CheckableInput */
fieldHelpInline: PropTypes.bool,
/** Unique Identifier for the input. Will use a randomly generated GUID if none is provided */
inputId: PropTypes.string,
id: PropTypes.string,
/** Specifies input type, 'checkbox' or 'radio' */
inputType: PropTypes.string.isRequired,
type: PropTypes.string.isRequired,
/** Value passed to the input */
inputValue: PropTypes.string,
value: PropTypes.string,
/** Sets percentage-based input width */
inputWidth: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
/** The content for the Label to apply to the input */
Expand All @@ -161,8 +162,6 @@ CheckableInput.propTypes = {
reverse: PropTypes.bool,
/** Flag to configure component as mandatory */
required: PropTypes.bool,
/** Input tabindex */
tabindex: PropTypes.string,
/** A callback to retrieve the input reference */
inputRef: PropTypes.oneOfType([
PropTypes.func,
Expand Down
34 changes: 14 additions & 20 deletions src/__internal__/checkable-input/checkable-input.d.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import * as React from "react";

import { ValidationPropTypes } from "../validations";
import { CommonHiddenCheckableInputProps } from "./hidden-checkable-input";

export interface CommonCheckableInputProps extends ValidationPropTypes {
/** Set the value of the CheckableInput */
checked?: boolean;
export interface CommonCheckableInputProps
extends ValidationPropTypes,
CommonHiddenCheckableInputProps {
/** If true, the component will be disabled */
disabled?: boolean;
/** Help content to be displayed under an input */
Expand All @@ -13,47 +15,39 @@ export interface CommonCheckableInputProps extends ValidationPropTypes {
* To be used with labelInline prop set to true
*/
fieldHelpInline?: boolean;
/** Unique Identifier for the input. Will use a randomly generated GUID if none is provided */
id?: string;
/** Sets percentage-based input width */
inputWidth?: number | string;
/** Label content */
label?: React.ReactNode;
/** The content for the help tooltip, to appear next to the Label */
labelHelp?: string | React.ReactNode;
/** Spacing between label and a field for inline label, given number will be multiplied by base spacing unit (8) */
labelSpacing?: 1 | 2;
/** Label width */
labelWidth?: number;
/** The name of the the input */
name?: string;
/** Specify a callback triggered on blur */
onBlur?: (ev: React.FocusEvent<HTMLInputElement>) => void;
/** Specify a callback triggered on focus */
onFocus?: (ev: React.FocusEvent<HTMLInputElement>) => void;
/** Specify a callback triggered on change */
onChange?: (ev: React.ChangeEvent<HTMLInputElement>) => void;
/** Flag to configure component as mandatory */
required?: boolean;
/** If true the label switches position with the input */
reverse?: boolean;
/** Size of the component */
size?: "small" | "large";
}

export interface CheckableInputProps extends CommonCheckableInputProps {
/** Used to set the visible aspect of the input (i.e. the checkbox sprite, input slider etc) */
children?: React.ReactNode;
/** Unique Identifier for the input. Will use a randomly generated GUID if none is provided */
inputId?: string;
/** HTML type attribute of the input */
inputType?: string;
type: string;
/** Value passed to the input */
inputValue?: string;
value?: string;
/** Text alignment of the label */
labelAlign?: "left" | "right";
/** A message that the Help component will display */
labelHelp?: React.ReactNode;
/** When true label is inline */
labelInline?: boolean;
}

declare class CheckableInput extends React.Component<
CheckableInputProps & React.HTMLProps<HTMLInputElement>
> {}
declare function CheckableInput(props: CheckableInputProps): JSX.Element;

export default CheckableInput;
19 changes: 6 additions & 13 deletions src/__internal__/checkable-input/checkable-input.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ import React from "react";
import TestRenderer from "react-test-renderer";
import { mount } from "enzyme";
import { css } from "styled-components";

import { assertStyleMatch } from "../../__spec_helper__/test-utils";
import CheckableInput from ".";
import FieldHelpStyle from "../field-help/field-help.style";
import { FieldLineStyle } from "../form-field/form-field.style";
import Label from "../label";
import HiddenCheckableInputStyle from "./hidden-checkable-input.style";
import LabelStyle, { StyledLabelContainer } from "../label/label.style";
import {
Expand All @@ -23,27 +23,20 @@ function render(props) {
describe("CheckableInput", () => {
function mountInput(props) {
return mount(
<CheckableInput
inputType="text"
inputValue=""
onChange={() => null}
{...props}
/>
<CheckableInput type="text" value="" onChange={() => null} {...props} />
);
}

describe("helpId", () => {
describe("when label and labelHelp props are present", () => {
it("returns an appropriate helpId property", () => {
it("passes an appropriate helpId property to Help component", () => {
const labelWrapper = mountInput({
inputId: "foo",
id: "foo",
label: "bar",
labelHelp: "baz",
})
.find(Label)
.find("label");
}).find(StyledHelp);

expect(labelWrapper.prop("id")).toBe("foo label");
expect(labelWrapper.prop("id")).toBe("foo help");
});
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@ import { InputContext, InputGroupContext } from "../input-behaviour";

const HiddenCheckableInput = ({
helpId,
labelId,
name,
inputType,
inputValue,
tabindex,
checked,
type,
value,
inputRef,
onChange,
autoFocus,
...props
}) => {
const { onBlur, onFocus, onMouseEnter, onMouseLeave } = useContext(
Expand All @@ -36,45 +37,61 @@ const HiddenCheckableInput = ({
};

const handleMouseEnter = (ev) => {
if (props.onMouseEnter) props.onMouseEnter(ev);
if (onMouseEnter) onMouseEnter(ev);
if (onMouseEnterGroup) onMouseEnterGroup(ev);
};

const handleMouseLeave = (ev) => {
if (props.onMouseLeave) props.onMouseLeave(ev);
if (onMouseLeave) onMouseLeave(ev);
if (onMouseLeaveGroup) onMouseLeaveGroup(ev);
};

return (
<HiddenCheckableInputStyle
aria-checked={props.checked}
aria-labelledby={labelId}
autoFocus={autoFocus}
aria-checked={checked}
checked={checked}
aria-describedby={helpId}
name={name}
role={inputType}
tabIndex={tabindex}
type={inputType}
value={inputValue}
role={type}
type={type}
value={value}
{...props}
onFocus={handleFocus}
onBlur={handleBlur}
onMouseEnter={handleMouseEnter}
onMouseLeave={handleMouseLeave}
onChange={onChange}
ref={inputRef}
/>
);
};

HiddenCheckableInput.propTypes = {
/** Allows component to be focused on page load */
autoFocus: PropTypes.bool,
/** Checked state of the input */
checked: PropTypes.bool,
labelId: PropTypes.string,
/** Element id for aria-describedby */
helpId: PropTypes.string,
/** Input name */
name: PropTypes.string,
onBlur: PropTypes.func,
/** OnChange event handler */
onChange: PropTypes.func,
/** OnFocus event handler */
onFocus: PropTypes.func,
inputType: PropTypes.string.isRequired,
inputValue: PropTypes.string,
tabindex: PropTypes.number,
/** Blur event handler */
onBlur: PropTypes.func,
/** OnMouseLeave event handler */
onMouseLeave: PropTypes.func,
/** OnMouseEnter event handler */
onMouseEnter: PropTypes.func,
/** HTML type attribute of the input */
type: PropTypes.string.isRequired,
/** Value of the input */
value: PropTypes.string,
/** A callback to retrieve the input reference */
inputRef: PropTypes.oneOfType([
PropTypes.func,
Expand Down
Loading

0 comments on commit 887fc58

Please sign in to comment.