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

Updating Label component #17731

Merged
merged 1 commit into from
Feb 15, 2023
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,11 @@ export const FormTextField = ({
<Label
htmlFor={id}
required={required}
disabled={disabled}
{...labelProps}
className={classnames(
'mm-form-text-field__label',
labelProps?.className,
)}
>
{label}
</Label>
Expand Down Expand Up @@ -105,13 +108,13 @@ export const FormTextField = ({
/>
{helpText && (
<HelpText
error={error}
marginTop={1}
{...helpTextProps}
className={classnames(
'mm-form-text-field__help-text',
helpTextProps?.className,
)}
error={error}
marginTop={1}
{...helpTextProps}
Copy link
Contributor Author

@georgewrmarshall georgewrmarshall Feb 11, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ensures the default className isn't overridden. Have added test to check

>
{helpText}
</HelpText>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
.mm-form-text-field {
--help-text-opacity-disabled: 0.5;
--text-opacity-disabled: 0.5;

&--disabled {
.mm-form-text-field__label,
.mm-form-text-field__help-text {
opacity: var(--help-text-opacity-disabled);
opacity: var(--text-opacity-disabled);
cursor: default;
}
}
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need to move disabled styles to FormTextField

Original file line number Diff line number Diff line change
Expand Up @@ -96,11 +96,14 @@ describe('FormTextField', () => {
const { getByText, getByTestId } = render(
<FormTextField
helpText="test help text"
helpTextProps={{ 'data-testid': 'help-text-test' }}
helpTextProps={{ 'data-testid': 'help-text-test', className: 'test' }}
/>,
);
expect(getByText('test help text')).toBeDefined();
expect(getByTestId('help-text-test')).toBeDefined();
expect(getByTestId('help-text-test')).toHaveClass(
'mm-form-text-field__help-text test',
);
});
// id
it('should render the FormTextField with an id and pass it to input and Label as htmlFor. When clicking on Label the input should have focus', async () => {
Expand Down Expand Up @@ -141,12 +144,15 @@ describe('FormTextField', () => {
const { getByTestId, getByLabelText } = render(
<FormTextField
label="test label"
labelProps={{ 'data-testid': 'label-test-id' }}
labelProps={{ 'data-testid': 'label-test-id', className: 'test' }}
id="test-id"
/>,
);
expect(getByLabelText('test label')).toBeDefined();
expect(getByTestId('label-test-id')).toBeDefined();
expect(getByTestId('label-test-id')).toHaveClass(
'mm-form-text-field__label test',
);
});
// leftAccessory, // rightAccessory
it('should render with right and left accessories', () => {
Expand Down
8 changes: 0 additions & 8 deletions ui/components/component-library/label/README.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -82,14 +82,6 @@ import { Label } from '../../component-library';
<Label required>Label</Label>;
```

### Disabled

Use the `disabled` prop to set the `Label` in disabled state

<Canvas>
<Story id="components-componentlibrary-label--disabled" />
</Canvas>

```jsx
import { Label } from '../../component-library';

Expand Down
17 changes: 2 additions & 15 deletions ui/components/component-library/label/label.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,14 @@ import {
AlignItems,
} from '../../../helpers/constants/design-system';

export const Label = ({
htmlFor,
required,
disabled,
className,
children,
...props
}) => (
export const Label = ({ htmlFor, required, className, children, ...props }) => (
<Text
className={classnames(
'mm-label',
{ 'mm-label--disabled': disabled },
{ 'mm-label--html-for': htmlFor && !disabled },
{ 'mm-label--html-for': htmlFor },
className,
)}
as="label"
disabled={disabled}
htmlFor={htmlFor}
variant={TextVariant.bodyMd}
fontWeight={FONT_WEIGHT.BOLD}
Expand Down Expand Up @@ -61,10 +52,6 @@ Label.propTypes = {
* If true the label will display as required
*/
required: PropTypes.bool,
/**
* Whether the label is disabled or not
*/
disabled: PropTypes.bool,
/**
* Additional classNames to be added to the label component
*/
Expand Down
6 changes: 0 additions & 6 deletions ui/components/component-library/label/label.scss
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
.mm-label {
--label-opacity-disabled: 0.5; // TODO: replace with design token

&--html-for {
cursor: pointer;
}

&--disabled {
opacity: var(--label-opacity-disabled);
}
}
8 changes: 0 additions & 8 deletions ui/components/component-library/label/label.stories.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,6 @@ export default {
required: {
control: 'boolean',
},
disabled: {
control: 'boolean',
},
children: {
control: 'text',
},
Expand Down Expand Up @@ -104,8 +101,3 @@ export const Required = Template.bind({});
Required.args = {
required: true,
};

export const Disabled = Template.bind({});
Disabled.args = {
disabled: true,
};
4 changes: 0 additions & 4 deletions ui/components/component-library/label/label.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,4 @@ describe('label', () => {
expect(getByText('label')).toBeDefined();
expect(getByText('*')).toBeDefined();
});
it('should render with disabled state and have disabled class', () => {
const { getByText } = render(<Label disabled>label</Label>);
expect(getByText('label')).toHaveClass('mm-label--disabled');
});
});