Skip to content

Commit

Permalink
fix: immutable text not rendering in docs (and when used in maas-ui)
Browse files Browse the repository at this point in the history
  • Loading branch information
ndv99 committed Apr 30, 2024
1 parent c671a02 commit fb91676
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/lib/elements/LimitedInput/LimitedInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,12 @@ export const LimitedInput = ({
}: LimitedInputProps) => {
const limitedInputRef: RefObject<HTMLDivElement> = useRef(null);

const inputWrapper = limitedInputRef.current?.firstElementChild;

useEffect(() => {
const inputWrapper = limitedInputRef.current?.firstElementChild;
if (inputWrapper) {
if (props.label) {
// CSS variable "--immutable" is the content of the :before element, which shows the immutable octets
// "--top" is the `top` property of the :before element, which is adjusted if there is a label to prevent overlap
inputWrapper.setAttribute(
"style",
`--top: 2.5rem; --immutable: "${immutableText}"`,
Expand All @@ -35,12 +36,14 @@ export const LimitedInput = ({

const width = window.getComputedStyle(inputWrapper, ":before").width;

// Adjust the left padding of the input to be the same width as the immutable octets.
// This displays the user input and the unchangeable text together as one IP address.
inputWrapper.lastElementChild?.firstElementChild?.setAttribute(
"style",
`padding-left: ${width}`,
);
}
}, [inputWrapper]);
}, [limitedInputRef, immutableText, props.label]);

return (
<div className="limited-input" ref={limitedInputRef}>
Expand Down

0 comments on commit fb91676

Please sign in to comment.