Skip to content

Commit

Permalink
feat: improve read-only behaviour (PDS-200) (#502)
Browse files Browse the repository at this point in the history
  • Loading branch information
reme3d2y committed Feb 11, 2021
1 parent 0b3c159 commit 3b3c5e6
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ export const AutocompleteField = ({
}: AutocompleteFieldProps) => {
const inputRef = useRef<HTMLInputElement>(null);

const { onClick } = innerProps;
const { onClick, onFocus } = innerProps;

const inputDisabled = disabled || readOnly;

const handleClick = useCallback(
event => {
Expand Down Expand Up @@ -53,7 +55,8 @@ export const AutocompleteField = ({
success={success}
hint={hint}
onChange={onInput}
onClick={handleClick}
onClick={inputDisabled ? undefined : handleClick}
onFocus={inputDisabled ? undefined : onFocus}
autoComplete='off'
value={value}
rightAddons={
Expand Down
6 changes: 4 additions & 2 deletions packages/input/src/Component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -209,13 +209,15 @@ export const Input = React.forwardRef<HTMLInputElement, InputProps>(

const handleInputFocus = useCallback(
(event: React.FocusEvent<HTMLInputElement>) => {
setFocused(true);
if (!readOnly) {
setFocused(true);
}

if (onFocus) {
onFocus(event);
}
},
[onFocus],
[onFocus, readOnly],
);

const handleInputBlur = useCallback(
Expand Down
22 changes: 15 additions & 7 deletions packages/input/src/index.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -95,13 +95,6 @@
color: var(--input-disabled-color);
}

/* READ-ONLY STATE */

.input:read-only {
cursor: var(--disabled-cursor);
color: var(--input-read-only-color);
}

/* FOCUS STATE */

.input:focus.hasLabel::placeholder {
Expand All @@ -116,6 +109,21 @@
@mixin focus-outline;
}

/* READ-ONLY STATE */

.input:read-only {
cursor: var(--disabled-cursor);
color: var(--input-read-only-color);

&:focus::placeholder {
color: var(--input-placeholder-color);
}
}

.hasLabel:read-only:focus::placeholder {
opacity: 0;
}

/* IE hide clear */

.input::-ms-clear {
Expand Down
2 changes: 1 addition & 1 deletion packages/with-suffix/src/index.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
pointer-events: none;
}

input:focus + .suffixContainer,
input:focus:not(:read-only) + .suffixContainer,
.suffixVisible .suffixContainer {
display: inline-flex;
}
Expand Down

0 comments on commit 3b3c5e6

Please sign in to comment.