-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Enhance error list functionality: improve scrolling and focus behavio…
…r for error links Refs: #7310
- Loading branch information
Showing
3 changed files
with
74 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
62 changes: 38 additions & 24 deletions
62
packages/samples/react/src/components/form/error-list.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,42 @@ | ||
import { KolButton, KolForm, KolInputText } from '@public-ui/react'; | ||
import type { FC } from 'react'; | ||
import React from 'react'; | ||
import React, { useRef } from 'react'; | ||
import { SampleDescription } from '../SampleDescription'; | ||
import { KolForm, KolInputText } from '@public-ui/react'; | ||
|
||
export const FormErrorList: FC = () => ( | ||
<> | ||
<SampleDescription> | ||
<p>This sample shows a form with error messages.</p> | ||
</SampleDescription> | ||
export const FormErrorList: FC = () => { | ||
const formRef = useRef<HTMLKolFormElement>(); | ||
return ( | ||
<> | ||
<SampleDescription> | ||
<p>This sample shows a form with error messages.</p> | ||
</SampleDescription> | ||
|
||
<KolForm | ||
className="w-full" | ||
_errorList={[ | ||
{ | ||
message: 'Error in Input 2', | ||
selector: '#input2', | ||
}, | ||
]} | ||
> | ||
<div className="grid gap-2"> | ||
<KolInputText id="input1" _label="Input 1" /> | ||
<KolInputText id="input2" _label="Input 2" _touched _msg={{ _description: 'Input error', _type: 'error' }} /> | ||
<KolInputText id="input3" _label="Input 3" /> | ||
</div> | ||
</KolForm> | ||
</> | ||
); | ||
<KolForm | ||
className="w-full" | ||
ref={formRef} | ||
_errorList={[ | ||
{ | ||
message: 'Error in Input 2', | ||
selector: '#input2', | ||
}, | ||
]} | ||
> | ||
<div className="grid gap-2"> | ||
<KolInputText id="input1" _label="Input 1" /> | ||
<KolInputText id="input2" _label="Input 2" _touched _msg={{ _description: 'Input error', _type: 'error' }} /> | ||
<KolInputText id="input3" _label="Input 3" /> | ||
<div> | ||
<KolButton | ||
_label="ScrollTo" | ||
_on={{ | ||
onClick: () => { | ||
formRef.current?.focusErrorList(); | ||
}, | ||
}} | ||
/> | ||
</div> | ||
</div> | ||
</KolForm> | ||
</> | ||
); | ||
}; |