Skip to content

Commit 139f7f1

Browse files
committed
fix(many): fix regression where form elements without label got misaligned
1 parent 90e0af4 commit 139f7f1

File tree

19 files changed

+84
-52
lines changed

19 files changed

+84
-52
lines changed

docs/guides/form-errors.md

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,9 @@ However you might have noticed from the type definition that a message can be `e
5151

5252
We wanted to allow users to start using the new format without making it mandatory, but after the introductory period `newError` will be deprecated and `error` type will be changed to look and behave the same way.
5353

54-
With this update we also introduced the "required asterisk" which will display an `*` character next to field labels that are required. This update is not opt-in and will apply to **all** InstUI form components so if you we relying on a custom solution for this feature before, you need to remove that to avoid having double asterisks.
54+
With this update we also introduced the "required asterisk" which will display an `*` character next to field labels that are required. This update is not opt-in and will apply to **all** InstUI form components so if you were relying on a custom solution for this feature before, you need to remove that to avoid having double asterisks.
5555

56-
Here are examples with different form components:
56+
Here are examples with different form components:
5757

5858
```ts
5959
---
@@ -98,7 +98,7 @@ const Example = () => {
9898
<TextArea messages={messages} label="TextArea" required={isRequired}/>
9999

100100
<Checkbox label="Checkbox" isRequired={isRequired} messages={messages}/>
101-
101+
102102
<Checkbox label={`Checkbox (variant="toggle")`} variant="toggle" isRequired={isRequired} messages={messages}/>
103103

104104
<CheckboxGroup
@@ -127,6 +127,14 @@ const Example = () => {
127127
</RadioInputGroup>
128128

129129
<FileDrop messages={messages} renderLabel="FileDrop" />
130+
131+
<ColorPicker
132+
label="ColorPicker"
133+
placeholderText="Enter HEX"
134+
isRequired={isRequired}
135+
renderMessages={() => messages}
136+
/>
137+
130138
</div>
131139
</div>
132140
)

packages/ui-checkbox/src/Checkbox/index.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ class Checkbox extends Component<CheckboxProps, CheckboxState> {
230230
invalid={this.invalid}
231231
>
232232
{label}
233-
{isRequired && (
233+
{isRequired && label && (
234234
<span css={this.invalid ? styles?.requiredInvalid : {}}> *</span>
235235
)}
236236
</ToggleFacade>
@@ -247,7 +247,7 @@ class Checkbox extends Component<CheckboxProps, CheckboxState> {
247247
invalid={this.invalid}
248248
>
249249
{label}
250-
{isRequired && (
250+
{isRequired && label && (
251251
<span css={this.invalid ? styles?.requiredInvalid : {}}> *</span>
252252
)}
253253
</CheckboxFacade>

packages/ui-checkbox/src/Checkbox/props.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ type CheckboxOwnProps = {
4444
/**
4545
* Array of objects with shape: `{
4646
* text: ReactNode,
47-
* type: One of: ['error', 'hint', 'success', 'screenreader-only']
47+
* type: One of: ['newError', 'error', 'hint', 'success', 'screenreader-only']
4848
* }`
4949
*/
5050
messages?: FormMessage[]

packages/ui-color-picker/src/ColorPicker/index.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,7 @@ class ColorPicker extends Component<ColorPickerProps, ColorPickerState> {
268268
isRequiredMessages =
269269
typeof renderIsRequiredMessage === 'function'
270270
? renderIsRequiredMessage()
271-
: [{ type: 'error', text: '*' }]
271+
: [{ type: 'error', text: '' }]
272272
}
273273
if (typeof renderMessages === 'function') {
274274
generalMessages = renderMessages(
@@ -386,14 +386,14 @@ class ColorPicker extends Component<ColorPickerProps, ColorPickerState> {
386386
const { label, tooltip, styles } = this.props
387387

388388
return tooltip ? (
389-
<div>
389+
<span>
390390
<span css={styles?.label}>{label}</span>
391391
<span>
392392
<Tooltip renderTip={tooltip}>
393393
<IconInfoLine tabIndex={-1} />
394394
</Tooltip>
395395
</span>
396-
</div>
396+
</span>
397397
) : (
398398
label
399399
)

packages/ui-color-picker/src/ColorPicker/props.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ type ColorPickerOwnProps = {
5252
*
5353
* FormMessage[]: Array of objects with shape: `{
5454
* text: ReactNode,
55-
* type: One of: ['error', 'hint', 'success', 'screenreader-only']
55+
* type: One of: ['newError', 'error', 'hint', 'success', 'screenreader-only']
5656
* }`
5757
*/
5858
checkContrast?: {
@@ -164,7 +164,7 @@ type ColorPickerOwnProps = {
164164
*
165165
* FormMessage[]: Array of objects with shape: `{
166166
* text: ReactNode,
167-
* type: One of: ['error', 'hint', 'success', 'screenreader-only']
167+
* type: One of: ['newError', 'error', 'hint', 'success', 'screenreader-only']
168168
* }`
169169
*/
170170
renderInvalidColorMessage?: (hexCode: string) => FormMessage[]
@@ -174,7 +174,7 @@ type ColorPickerOwnProps = {
174174
*
175175
* FormMessage[]: Array of objects with shape: `{
176176
* text: ReactNode,
177-
* type: One of: ['error', 'hint', 'success', 'screenreader-only']
177+
* type: One of: ['newError', 'error', 'hint', 'success', 'screenreader-only']
178178
* }`
179179
*/
180180
renderIsRequiredMessage?: () => FormMessage[]
@@ -184,7 +184,7 @@ type ColorPickerOwnProps = {
184184
*
185185
* FormMessage[]: Array of objects with shape: `{
186186
* text: ReactNode,
187-
* type: One of: ['error', 'hint', 'success', 'screenreader-only']
187+
* type: One of: ['newError', 'error', 'hint', 'success', 'screenreader-only']
188188
* }`
189189
*/
190190
renderMessages?: (

packages/ui-form-field/src/FormField/props.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ type FormFieldOwnProps = {
4343
/**
4444
* Array of objects with shape: `{
4545
* text: React.ReactNode,
46-
* type: One of: ['error', 'hint', 'success', 'screenreader-only']
46+
* type: One of: ['newError', 'error', 'hint', 'success', 'screenreader-only']
4747
* }`
4848
*/
4949
messages?: FormMessage[]

packages/ui-form-field/src/FormFieldGroup/props.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ type FormFieldGroupOwnProps = {
4545
/**
4646
* Array of objects with shape: `{
4747
* text: React.ReactNode,
48-
* type: One of: ['error', 'hint', 'success', 'screenreader-only']
48+
* type: One of: ['newError', 'error', 'hint', 'success', 'screenreader-only']
4949
* }`
5050
*/
5151
messages?: FormMessage[]

packages/ui-form-field/src/FormFieldLayout/props.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ type FormFieldLayoutOwnProps = {
4848
/**
4949
* Array of objects with shape: `{
5050
* text: React.ReactNode,
51-
* type: One of: ['error', 'hint', 'success', 'screenreader-only']
51+
* type: One of: ['newError', 'error', 'hint', 'success', 'screenreader-only']
5252
* }`
5353
*/
5454
messages?: FormMessage[]
@@ -79,7 +79,9 @@ type FormFieldLayoutProps = FormFieldLayoutOwnProps &
7979
OtherHTMLAttributes<FormFieldLayoutOwnProps> &
8080
WithDeterministicIdProps
8181

82-
type FormFieldLayoutStyle = ComponentStyle<'formFieldLayout' | 'groupErrorMessage'>
82+
type FormFieldLayoutStyle = ComponentStyle<
83+
'formFieldLayout' | 'groupErrorMessage'
84+
>
8385

8486
const propTypes: PropValidators<PropKeys> = {
8587
label: PropTypes.node.isRequired,

packages/ui-form-field/src/FormFieldLayout/styles.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ const generateStyle = (
4242

4343
return {
4444
groupErrorMessage: {
45-
margin: '0.5rem',
45+
margin: '0.5rem 0',
4646
},
4747
formFieldLayout: {
4848
label: 'formFieldLayout',

packages/ui-form-field/src/FormFieldMessages/props.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ type FormFieldMessagesOwnProps = {
3838
/**
3939
* Array of objects with shape: `{
4040
* text: React.ReactNode,
41-
* type: One of: ['error', 'hint', 'success', 'screenreader-only']
41+
* type: One of: ['newError', 'error', 'hint', 'success', 'screenreader-only']
4242
* }`
4343
*/
4444
messages?: FormMessage[]

0 commit comments

Comments
 (0)