Skip to content

Commit

Permalink
[@mantine/core] PasswordInput: Fix incorrect styles when the componen…
Browse files Browse the repository at this point in the history
…t is wrapper with element with `data-disabled` attribute (#5149)
  • Loading branch information
rtivital committed Nov 7, 2023
1 parent f4f95a1 commit 557f091
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 2 deletions.
6 changes: 6 additions & 0 deletions docs/pages/core/password-input.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,12 @@ Note that when `rightSection` prop is used, visibility toggle button is not rend

<Demo data={PasswordInputDemos.error} />

## Disabled

When `disabled` prop is set, visibility toggle button is hidden:

<Demo data={PasswordInputDemos.disabled} />

<StylesApiSelectors component="PasswordInput" />

<Demo data={PasswordInputDemos.stylesApi} />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
width: 100%;
color: inherit;

[data-disabled] &,
.input[data-disabled] &,
&:disabled {
cursor: not-allowed;
}
Expand All @@ -51,4 +51,8 @@
height: var(--psi-button-size);
min-width: var(--psi-button-size);
min-height: var(--psi-button-size);

&:disabled {
display: none;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@ import { PasswordInput } from './PasswordInput';
export default { title: 'PasswordInput' };

export function Usage() {
return <PasswordInput placeholder="Your password" label="Your password" />;
return (
<div data-disabled>
<PasswordInput placeholder="Your password" label="Your password" />
</div>
);
}

export function Unstyled() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ export const PasswordInput = factory<PasswordInputFactory>((_props, ref) => {
const visibilityToggleButton = (
<ActionIcon<'button'>
{...getStyles('visibilityToggle')}
disabled={disabled}
radius={radius}
aria-hidden={!visibilityToggleButtonProps}
tabIndex={-1}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import React from 'react';
import { MantineDemo } from '@mantine/ds';
import { PasswordInput } from '@mantine/core';

const code = `
import { PasswordInput } from '@mantine/core';
function Demo() {
return (
<PasswordInput disabled label="Disabled password input" placeholder="Disabled password input" />
);
}
`;

function Demo() {
return (
<PasswordInput disabled label="Disabled password input" placeholder="Disabled password input" />
);
}

export const disabled: MantineDemo = {
type: 'code',
component: Demo,
code,
centered: true,
maxWidth: 340,
};
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,8 @@ export const DemoSections = {
name: '⭐ Demo: sections',
render: renderDemo(demos.sections),
};

export const DemoDisabled = {
name: '⭐ Demo: disabled',
render: renderDemo(demos.disabled),
};
1 change: 1 addition & 0 deletions src/mantine-demos/src/demos/core/PasswordInput/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ export { visibilityIcon } from './PasswordInput.demo.visibilityIcon';
export { controlledVisibility } from './PasswordInput.demo.controlledVisibility';
export { stylesApi } from './PasswordInput.demo.stylesApi';
export { sections } from './PasswordInput.demo.sections';
export { disabled } from './PasswordInput.demo.disabled';

0 comments on commit 557f091

Please sign in to comment.