- Confirm as Modal
- Example
- Get Dropdown/Selector Value
- Example
- `onChange` Template
Confirm as Modal
Tags: React, CSS, Modal, Semantic UI, actions, trigger
Example
代码语言:javascript复制<Button.Group>
<Button>
<Icon name="history" />
</Button>
<Button>
<Icon name="edit" />
</Button>
<Modal
trigger={(
<Button
icon
title="Delete Employee"
>
<Icon name="trash" />
</Button>
)}
header="Alert!"
content="If you delete this employee then all related data"
actions={[
{
key: 'yes',
content: 'Yes',
positive: true,
onClick: () => {
console.log(123);
},
},
{ key: 'no', content: 'No' },
]}
/>
</Button.Group>
- If we used
trigger
then it will be rendered as HTML code specified. (Usually we may render it as a button) - We may render each action button per provided objects in attribute
actions
- In the above example, we may render 2 action buttons:
Yes
Button with on click eventNo
Button without any binded event
- In the above example, we may render 2 action buttons:
Get Dropdown/Selector Value
Tags: React, Semantic UI, selector, value, selected option, dropdown
event.target.value
isundefined
fromevent:onChange
ofDropdown
in Semantic UI
Example
Simply reach the second argument to get the value:
代码语言:javascript复制<Select
placeholder="Select An Employee"
options={props.employees}
value={props.employeeId}
title="employeeId"
onChange={(e, res) => {
const { title, value } = props;
// title = employeeId
// value = option value
}}
/>
onChange
Template
代码语言:javascript复制/* only for dropdown */
handleDropdownChange (props, e) {
const { name, value } = props
// ...
}
/* only for inputs */
handleInputChange (props, e) {
const { name, value } = props
// ...
}
Capture Form Inputs
代码语言:javascript复制For form inputs we can also capture the input via second argument
handleChange = (e, { name, value }) => this.setState({ [name]: value })
render() {
const { name, email, submittedName, submittedEmail } = this.state
return (
<div>
<Form onSubmit={this.handleSubmit}>
<Form.Group>
<Form.Input
placeholder='Name'
name='name'
value={name}
onChange={this.handleChange}
/>
<Form.Input
placeholder='Email'
name='email'
value={email}
onChange={this.handleChange}
/>
<Form.Button content='Submit' />
</Form.Group>
</Form>
<strong>onChange:</strong>
<pre>{JSON.stringify({ name, email }, null, 2)}</pre>
<strong>onSubmit:</strong>
<pre>{JSON.stringify({ submittedName, submittedEmail }, null, 2)}</pre>
</div>
)
}
See full instruction: https://react.semantic-ui.com/collections/form/#usage-capture-values
Reference
https://react.semantic-ui.com/modules/modal/#types-shorthand