Skip to content

Commit

Permalink
fix: correct field data display (placeholder), #166
Browse files Browse the repository at this point in the history
  • Loading branch information
nshenderov committed Oct 4, 2024
1 parent c74bcd8 commit b5f0991
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 15 deletions.
16 changes: 15 additions & 1 deletion admin/src/Input/components/Editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export const Editor = ({
disabled = false,
presetName,
maxLength,
placeholder
}) => {
const [editorInstance, setEditorInstance] = useState(false);

Expand All @@ -42,7 +43,20 @@ export const Editor = ({
presetName,
handleToggleMediaLib
);
setPreset(currentPreset);

if (placeholder) {
const clonedPreset = {
...currentPreset,
editorConfig: {
...currentPreset.editorConfig,
placeholder: placeholder.defaultMessage,
},
};

setPreset(clonedPreset);
} else {
setPreset(currentPreset);
}
})();
}, []);

Expand Down
31 changes: 17 additions & 14 deletions admin/src/Input/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,19 @@ import { Stack } from '@strapi/design-system';

import { Editor } from './components/Editor';

const Wysiwyg = React.forwardRef((props, ref) => {
const {
name,
attribute,
onChange,
value,
intlLabel,
labelAction,
disabled,
error,
description,
required,
} = props;
const Wysiwyg = ({
name,
attribute,
onChange,
value,
intlLabel,
labelAction,
disabled,
error,
description,
required,
placeholder,
}) => {
const { formatMessage } = useIntl();
const { preset, maxLengthCharacters, ...options } = attribute.options;

Expand All @@ -44,13 +44,14 @@ const Wysiwyg = React.forwardRef((props, ref) => {
value={value}
presetName={preset}
maxLength={maxLengthCharacters}
placeholder={placeholder}
/>
<FieldHint />
<FieldError />
</Stack>
</Field>
);
});
};

Wysiwyg.propTypes = {
intlLabel: PropTypes.object.isRequired,
Expand All @@ -63,5 +64,7 @@ Wysiwyg.propTypes = {
labelAction: PropTypes.object,
required: PropTypes.bool,
value: PropTypes.string,
placeholder: PropTypes.object,
};

export default Wysiwyg;
5 changes: 5 additions & 0 deletions admin/src/Input/theme/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -227,4 +227,9 @@ export const common = css`
}
}
}
.ck.ck-editor__editable > .ck-placeholder::before {
color: var(--ck-color-editor-base-text);
opacity: 0.65;
}
`;

0 comments on commit b5f0991

Please sign in to comment.