React 아코디언 개요
Ignite UI for React 클릭 가능한 헤더와 연관된 콘텐츠 섹션이 있는 수직 확장 패널을 구축하기 위한 GUI 구성 요소로, 단일 컨테이너에 표시됩니다. 아코디언은 일반적으로 단일 페이지에서 여러 콘텐츠 섹션을 스크롤할 필요성을 줄이는 데 사용됩니다. 키보드 탐색 및 기본 패널의 확장 상태를 제어하는 API를 제공합니다.
사용자는 썸네일이나 라벨과 같은 항목 목록 간에 상호 작용하고 탐색할 수 있습니다. 포함된 정보를 표시하기 위해 각 항목을 전환(확장 또는 축소)할 수 있습니다. 구성에 따라 한 번에 하나 또는 여러 개의 확장된 항목이 있을 수 있습니다.
React Accordion Example
다음은 FAQ 섹션의 기본 Ignite UI for React Accordion 예입니다. 개별적으로 작동하는 섹션이 있는 아코디언으로 작동합니다. 여러 패널을 동시에 확장하는 동안 한 번의 클릭으로 각 텍스트 블록을 토글할 수 있습니다. 이렇게 하면 이전에 열었던 섹션을 매번 숨기는 자동 확장 및 축소 패널 사이를 오가며 이동하지 않고도 정보를 더 쉽게 읽을 수 있습니다.
여기서는 아코디언과 해당 확장 패널을 정의하는 방법을 볼 수 있습니다. 또한 이 샘플은 두 가지 유형의 확장 동작을 보여줍니다. 스위치 버튼은 한 번에 확장할 단일 분기와 다중 분기 사이를 전환하도록 singleExpand
속성을 설정합니다.
import React, { useState } from 'react';
import ReactDOM from 'react-dom/client';
import './index.css';
import './AccordionOverview.css';
import {
IgrAccordion, IgrExpansionPanel, IgrSwitch,
IgrCheckboxChangeEventArgs } from "@infragistics/igniteui-react";
import 'igniteui-webcomponents/themes/light/bootstrap.css';
export default function AccordionOverview() {
const [singleExpand, setSingleExpand] = useState<boolean>(false);
const switchChange = (e: IgrCheckboxChangeEventArgs) => {
setSingleExpand(e.detail.checked);
}
return (
<div id="root">
<IgrSwitch onChange={switchChange}><span>Single Expand</span></IgrSwitch>
<div className="sample-wrapper">
<IgrAccordion singleExpand={singleExpand}>
<IgrExpansionPanel>
<h1 slot="title">What has changed about subscription and pricing model?</h1>
<span>We have moved to a subscription-based pricing model for all our developer tools. This makes it easier
for you to manage your license subscriptions and allows us to provide a better level of service for you. We
updated our pricing and packages to provide you with flexible options and the best value. This includes Ignite UI
(formerly Ignite UI for JavaScript) which includes all of our JavaScript framework components for web development,
including: Angular, ASP.NET (Core and MVC), Blazor, JQuery, React and Web Components, as well as Infragistics Professional,
Infragistics Ultimate, our Ultimate UI products. We also offer multi-year subscriptions options with a built-in discount,
so you can see the value up front. With these updates we are confident that we are providing the best platforms and the best
price.</span>
</IgrExpansionPanel>
<IgrExpansionPanel>
<h1 slot="title">Who will the updated changes impact?</h1>
<span>The license updates will impact all new and current customers using Ignite UI, Infragistics Professional and
Infragistics Ultimate. Specifically, we have also made updates to our product and packaging for Ignite UI for JavaScript,
Ignite UI for Angular, Ignite UI for React and Ignite UI for Web components. For more information, please refer to this
blog: Announcement: Changes to Ignite UI Product & Packaging The pricing has been updated for all products and packages.
So, all new or additional licenses will be sold based on our new pricing and packages. All existing license agreements will
be honored and renewed based upon the current agreement.</span>
</IgrExpansionPanel>
<IgrExpansionPanel>
<h1 slot="title">What is the difference between your old model and your current subscription model for Ignite UI?</h1>
<span>For Ignite UI customers, we are moving away from NPM for licensed packages. The current NPM packages will be replaced with
packages that include a “Trial Version” watermark. Licensed packages for Ignite UI will be available from our cloud hosted ProGet
server. For more information, please refer to this article: Moving from Trial to Licensed Ignite UI NPM Packages</span>
</IgrExpansionPanel>
<IgrExpansionPanel>
<h1 slot="title">What happens if I don't renew my subscription?</h1>
<span>Any unlicensed or trial versions of Ignite UI for Angular, React and Web Components will now include this watermark.</span>
</IgrExpansionPanel>
<IgrExpansionPanel>
<h1 slot="title">If I don't renew my subscription will I still have access to previous versions of Infragistics products?</h1>
<span>Any version of Infragistics software which you have downloaded can continue to be used perpetually. Access to download any new or
previous versions through our customer portal and package feeds will require maintaining an active subscription by continuing
to renew it.</span>
</IgrExpansionPanel>
</IgrAccordion>
</div>
</div>
);
}
// rendering above component to the React DOM
const root = ReactDOM.createRoot(document.getElementById('root'));
root.render(<AccordionOverview />);
tsxigc-accordion {
width: 100%;
}
.sample-wrapper {
overflow-y: auto;
max-height: 380px;
margin: 8px;
}
igc-switch {
padding: 16px;
}
igc-expansion-panel {
border: 1px solid rgba(174, 174, 174, 0.25);
}
css
Like this sample? Get access to our complete Ignite UI for React toolkit and start building your own apps in minutes. Download it for free.
Getting Started with React Accordion
먼저, 다음 명령을 실행하여 Ignite UI for React 설치해야 합니다.
npm install igniteui-react
cmd
그런 다음 다음과 같이 와 IgrAccordion
및 IgrExpansionPanel
및 필요한 CSS를 가져와야 합니다.
import {
IgrAccordion,
IgrExpansionPanel,
} from "igniteui-react";
import "igniteui-webcomponents/themes/light/bootstrap.css";
tsx
이제 및 해당 패널의 IgrAccordion
기본 구성으로 시작할 수 있습니다.
Usage
React Accordion Component의 각 섹션은 React 확장 패널을 사용하여 정의됩니다. 패널은 Disabled
및 Open
속성을 제공하며, 이를 통해 요구 사항에 따라 패널 상태를 구성할 수 있습니다.
Declaring an Accordion
아코디언은 그 안에 선언 된 모든 확장 패널을 감쌉니다.
<IgrAccordion singleExpand={true}>
<IgrExpansionPanel>
<div slot="title">Title Panel 1</div>
<div>Content Panel 1</div>
</IgrExpansionPanel>
<IgrExpansionPanel>
<div slot="title">Title Panel 2</div>
<div>Content Panel 2</div>
</IgrExpansionPanel>
</IgrAccordion>
tsx
위에서 설명한 것처럼, singleExpand
속성을 사용하면 한 번에 단일 패널 또는 여러 패널을 확장할 수 있는지 여부를 설정할 수 있습니다.
and showAll
메서드를 사용하면 hideAll
프로그래밍 방식으로 모든 IgrExpansionPanel
s를 IgrAccordion
각각 축소 및 확장할 수 있습니다.
If singleExpand property is set to true calling showAll method would expand only the focused panel.
React Accordion Customization Example
React Accordion을 사용하면 헤더와 콘텐츠 패널의 모양을 사용자 지정할 수 있습니다.
아래 샘플은 기본 제공 슬롯 IgrExpansionPanel
을 사용하여 정교한 필터링 옵션을 구현하는 방법을 보여줍니다.
import React from "react";
import ReactDOM from "react-dom/client";
import "./index.css";
import "./AccordionCustomization.css";
import {
IgrAccordion,
IgrCheckbox,
IgrCheckboxChangeEventArgs,
IgrDateTimeInput,
IgrExpansionPanel,
IgrIcon,
IgrRadio,
IgrRadioGroup,
IgrRating,
IgrRangeSlider,
IgrRadioChangeEventArgs,
IgrRangeSliderValueEventArgs,
IgrComponentDateValueChangedEventArgs,
registerIconFromText,
} from "@infragistics/igniteui-react";
import "igniteui-webcomponents/themes/light/bootstrap.css";
type Category = { checked: boolean; type: string };
const clearIcon =
"<svg xmlns='http://www.w3.org/2000/svg' xmlns:xlink='http://www.w3.org/1999/xlink' version='1.1' width='24' height='24' viewBox='0 0 24 24'><path d='M19,6.41L17.59,5L12,10.59L6.41,5L5,6.41L10.59,12L5,17.59L6.41,19L12,13.41L17.59,19L19,17.59L13.41,12L19,6.41Z' /></svg>";
const clockIcon =
"<svg xmlns='http://www.w3.org/2000/svg' xmlns:xlink='http://www.w3.org/1999/xlink' version='1.1' width='24' height='24' viewBox='0 0 24 24'><path d='M12,20A8,8 0 0,0 20,12A8,8 0 0,0 12,4A8,8 0 0,0 4,12A8,8 0 0,0 12,20M12,2A10,10 0 0,1 22,12A10,10 0 0,1 12,22C6.47,22 2,17.5 2,12A10,10 0 0,1 12,2M12.5,7V12.25L17,14.92L16.25,16.15L11,13V7H12.5Z' /></svg>";
export default class AccordionCustomization extends React.Component<any, any> {
private categories = [
{ checked: false, type: "Bike" },
{ checked: false, type: "Motorcycle" },
{ checked: false, type: "Car" },
{ checked: false, type: "Taxi" },
{ checked: false, type: "Public Transport" },
];
private dateTimeInput: IgrDateTimeInput;
constructor(props: any) {
super(props);
this.state = {
categories: this.categories,
cost: { lower: 200, upper: 800 },
rating: "",
time: "Time",
};
this.categoriesChange = this.categoriesChange.bind(this);
this.costRangeChange = this.costRangeChange.bind(this);
this.ratingChange = this.ratingChange.bind(this);
this.timeChange = this.timeChange.bind(this);
this.clearTime = this.clearTime.bind(this);
this.dateTimeInputRef = this.dateTimeInputRef.bind(this);
registerIconFromText("clear", clearIcon, "material");
registerIconFromText("clock", clockIcon, "material");
}
public render(): JSX.Element {
return (
<div id="root">
<div className="sample-wrapper">
<IgrAccordion>
<IgrExpansionPanel>
<h1 slot="title">
Categories
{this.state.categories.some((c: Category) => c.checked) && ": "}
{this.state.categories
.filter((c: Category) => c.checked)
.map((c: Category) => c.type)
.join(", ")}
</h1>
<span>
<div className="categories-container">
{this.state.categories.map((c: Category) => {
return (
<IgrCheckbox
key={"checkbox-" + c.type}
onChange={(e: IgrCheckboxChangeEventArgs) =>
this.categoriesChange(e, c.type)
}
>
<span>{c.type}</span>
</IgrCheckbox>
);
})}
</div>
</span>
</IgrExpansionPanel>
<IgrExpansionPanel>
<h1 slot="title">
Cost: $<span id="lowerCost">{this.state.cost.lower}</span> to $
<span id="upperCost">{this.state.cost.upper}</span>
</h1>
<span>
<IgrRangeSlider
min={0}
max={1000}
lower={this.state.cost.lower}
upper={this.state.cost.upper}
onChange={this.costRangeChange}
></IgrRangeSlider>
</span>
</IgrExpansionPanel>
<IgrExpansionPanel>
<h1 slot="title">
Rating{this.state.rating && ": "}
{this.state.rating}
</h1>
<span>
<IgrRadioGroup alignment="horizontal">
{[1, 2, 3, 4].map((rating) => {
return (
<IgrRadio
key={`${rating}star`}
name="rating"
value={rating.toString()}
onChange={this.ratingChange}
>
<IgrRating
label={`${rating} star${
rating > 1 ? "s" : ""
} or more`}
max={5}
value={rating + 0.5}
className="size-small"
readOnly={true}
></IgrRating>
</IgrRadio>
);
})}
</IgrRadioGroup>
</span>
</IgrExpansionPanel>
<IgrExpansionPanel>
<h1 slot="title">
{this.state.time}
</h1>
<span>
<IgrDateTimeInput
className="size-small"
inputFormat="hh:mm tt"
label="Arrive before"
ref={this.dateTimeInputRef}
onChange={this.timeChange}
>
<span slot="prefix">
<IgrIcon name="clock" collection="material" />
</span>
<span slot="suffix" onClick={this.clearTime}>
<IgrIcon name="clear" collection="material" />
</span>
</IgrDateTimeInput>
</span>
</IgrExpansionPanel>
</IgrAccordion>
</div>
</div>
);
}
public categoriesChange(e: IgrCheckboxChangeEventArgs, type: string) {
const categoryIndex = this.categories.findIndex((c) => c.type === type);
if (categoryIndex === -1) {
return;
}
let categoriesCopy = this.state.categories;
categoriesCopy[categoryIndex].checked = e.detail.checked;
this.setState({
categories: categoriesCopy,
});
}
public costRangeChange(e: IgrRangeSliderValueEventArgs) {
this.setState({
cost: { lower: e.detail.lower, upper: e.detail.upper },
});
}
public ratingChange(e: IgrRadioChangeEventArgs) {
if (!e.detail.value) {
return;
}
this.setState({
rating: `${+e.detail.value} star${
+e.detail.value > 1 ? "s" : ""
} or more`,
});
}
public timeChange(e: IgrComponentDateValueChangedEventArgs) {
const s = e.target as IgrDateTimeInput;
const result =
s.value !== null
? `Arrive before ${e.detail.toLocaleTimeString([], {
hour: "2-digit",
minute: "2-digit",
})}`
: "Time";
this.setState({
time: result,
});
}
public clearTime() {
this.dateTimeInput.clear();
this.setState({
time: "Time",
});
}
public dateTimeInputRef(input: IgrDateTimeInput) {
if (!input) {
return;
}
this.dateTimeInput = input;
}
}
// rendering above component to the React DOM
const root = ReactDOM.createRoot(document.getElementById("root"));
root.render(<AccordionCustomization />);
tsxigc-accordion {
width: 100%;
}
.sample-wrapper {
overflow-y: auto;
max-height: 530px;
margin: 8px;
}
igc-range-slider {
margin: 24px;
}
.categories-container {
display: flex;
flex-flow: column nowrap;
}
igc-checkbox,
igc-radio {
margin: 4px 0;
}
igc-expansion-panel {
border: 1px solid rgba(174, 174, 174, 0.25);
}
igc-rating {
flex-direction: row;
}
.size-small {
--ig-size: var(--ig-size-small);
}
css
Nested React Accordions Scenario
다음 React Accordion 예제에서는 이 일반적인 애플리케이션 시나리오를 어떻게 진행할 수 있는지 보여주기 위해 복잡한 FAQ 섹션을 만들었습니다. 샘플에서 중첩된 IgrAccordion
확장 패널 내부에 아코디언을 추가하여 구현되었습니다.
import React, { useState } from 'react';
import ReactDOM from 'react-dom/client';
import './index.css';
import './AccordionNestedScenario.css';
import {
IgrAccordion, IgrExpansionPanel, IgrSwitch,
IgrCheckboxChangeEventArgs
} from "@infragistics/igniteui-react";
import 'igniteui-webcomponents/themes/light/bootstrap.css';
export default function AccordionNestedScenario() {
const [singleExpand, setSingleExpand] = useState<boolean>(false);
const switchChange = (e: IgrCheckboxChangeEventArgs) => {
setSingleExpand(e.detail.checked);
}
return (
<div id="root">
<IgrSwitch onChange={switchChange}><span>Single Expand</span></IgrSwitch>
<div className="sample-wrapper">
<IgrAccordion singleExpand={singleExpand}>
<IgrExpansionPanel>
<h1 slot="title">What has changed about subscription and pricing model?</h1>
<span>We have moved to a subscription-based pricing model for all our developer tools. This makes it easier
for you to manage your license subscriptions and allows us to provide a better level of service for you. We
updated our pricing and packages to provide you with flexible options and the best value. This includes Ignite UI
(formerly Ignite UI for JavaScript) which includes all of our JavaScript framework components for web development,
including: Angular, ASP.NET (Core and MVC), Blazor, JQuery, React and Web Components, as well as Infragistics Professional,
Infragistics Ultimate, our Ultimate UI products. We also offer multi-year subscriptions options with a built-in discount,
so you can see the value up front. With these updates we are confident that we are providing the best platforms and the best
price.</span>
</IgrExpansionPanel>
<IgrExpansionPanel>
<h1 slot="title">Who will the updated changes impact?</h1>
<span>The license updates will impact all new and current customers using Ignite UI, Infragistics Professional and
Infragistics Ultimate. Specifically, we have also made updates to our product and packaging for Ignite UI for JavaScript,
Ignite UI for Angular, Ignite UI for React and Ignite UI for Web components. For more information, please refer to this
blog: Announcement: Changes to Ignite UI Product & Packaging The pricing has been updated for all products and packages.
So, all new or additional licenses will be sold based on our new pricing and packages. All existing license agreements will
be honored and renewed based upon the current agreement.</span>
</IgrExpansionPanel>
<IgrExpansionPanel>
<h1 slot="title">What is the difference between your old model and your current subscription model for Ignite UI?</h1>
<span>For Ignite UI customers, we are moving away from NPM for licensed packages. The current NPM packages will be replaced with
packages that include a “Trial Version” watermark. Licensed packages for Ignite UI will be available from our cloud hosted ProGet
server. For more information, please refer to this article: Moving from Trial to Licensed Ignite UI NPM Packages</span>
</IgrExpansionPanel>
<IgrExpansionPanel>
<h1 slot="title">Common questions about renewal.</h1>
<span>
<IgrAccordion>
<IgrExpansionPanel>
<h1 slot="title">What happens if I don't renew my subscription?</h1>
<span>Any unlicensed or trial versions of Ignite UI for Angular, React and Web Components will now include this watermark.</span>
</IgrExpansionPanel>
<IgrExpansionPanel>
<h1 slot="title">If I don't renew my subscription will I still have access to previous versions of Infragistics products?</h1>
<span>Any version of Infragistics software which you have downloaded can continue to be used perpetually. Access to download any new or
previous versions through our customer portal and package feeds will require maintaining an active subscription by continuing
to renew it.</span>
</IgrExpansionPanel>
<IgrExpansionPanel>
<h1 slot="title">Will I be automatically charged for my renewal/ Can I be automatically charged for renewal?</h1>
<span>Any new subscriptions purchased online, via our eCommerce system, will renew automatically. Subscription renewal can be canceled,
at any time, before the next automatic renewal date. Subscriptions purchased directly from Infragistics or Infragistics' partners are
subject to the renewal terms that were agreed upon as part of that purchase.</span>
</IgrExpansionPanel>
</IgrAccordion>
</span>
</IgrExpansionPanel>
<IgrExpansionPanel>
<h1 slot="title">I split my work across two computers. Can I install on both using my single-user license?</h1>
<span>The Infragistics Ultimate license is tied to the user, and not the computer. That means you're welcome to install and use Ignite UI,
Infragistics Professional, and Infragistics Ultimate on any computer you use. However, if we notice a large number of activations using the
same license, we may contact you to verify this behavior.</span>
</IgrExpansionPanel>
<IgrExpansionPanel>
<h1 slot="title">I used up my trial for an earlier version of Infragistics Ultimate. Can I start a new trial when a major version is released?</h1>
<span>Yes! If you have tried a previous version in the past, and used up your 30-day trial, you can try the next major version for another 30 days!
You can do this in the following two ways:
<ul>
<li>If you have days remaining in your 30-day trial period for the current version (e.g., the
Version 15.1 Volume Release), use the Check for Update option inside the Platform Installer or
your account. You will be able to start a fresh trial for the next major version (e.g., 20.1
Volume Release)</li>
<li>If you have used up the 30-day trial for the previous major version (e.g., the 19.2 Volume
Release), simply download and install Infragistics Ultimate from our <a
href="https://www.infragistics.com/products/ultimate">website</a> (This will also allow you
to start a new trial.)</li>
</ul></span>
</IgrExpansionPanel>
</IgrAccordion>
</div>
</div>
);
}
// rendering above component to the React DOM
const root = ReactDOM.createRoot(document.getElementById('root'));
root.render(<AccordionNestedScenario />);
tsxigc-accordion {
width: 100%;
}
.sample-wrapper {
overflow-y: auto;
max-height: 470px;
margin: 8px;
}
igc-switch {
padding: 16px;
}
igc-expansion-panel {
border: 1px solid rgba(174, 174, 174, 0.25);
}
css
Keyboard Navigation
React Accordion의 키보드 탐색은 최종 사용자에게 다양한 키보드 상호 작용을 제공합니다. 이 기능은 기본적으로 활성화되어 있으며 최종 사용자가 패널을 쉽게 탐색할 수 있습니다.
Accordion 탐색은 W3C 접근성 표준을 준수하며 사용이 편리합니다.
주요 조합
- ↓- 포커스를 아래 패널로 이동합니다.
- ↑- 포커스를 위 패널로 이동합니다.
- Alt + ↓- 아코디언에서 초점이 맞춰진 패널 열기
- Alt + ↑- 아코디언에서 초점이 맞춰진 패널을 닫습니다.
- Shift + Alt + ↓- 활성화된 모든 패널 열기(singleExpand가 true로 설정된 경우 초점이 맞춰진 패널 열기)
- Shift + Alt + ↑- 활성화된 모든 패널을 닫습니다.
- 홈- 아코디언에서 활성화된 첫 번째 패널로 이동합니다.
- 끝- 아코디언에서 마지막으로 활성화된 패널로 이동합니다.