Handle events exposed by Microsoft Graph Toolkit components
Many Microsoft Graph Toolkit components emit custom events. Attaching event handlers to these events allows you to respond to them and control the behavior of your app.
Discover which events components emit
Each Microsoft Graph Toolkit component emits different events, specific to its functionality. To see the list of events emitted by the specific component, see the Events section of the documentation for that component.
Important
Some events, like itemClick
in the File list component, are emitted only when using the default template. If you use a custom template, you overwrite the default rendering that is responsible for emitting the event.
Add event handlers to events
Microsoft Graph Toolkit uses the standard EventTarget.dispatchEvent()
function to emit custom events in its components. To attach an event handler to a custom event emitted by a toolkit's component, use the standard EventTarget.addEventListener()
function.
For example, to handle the itemClick
event emitted by the File list component, add the following to your code.
document.querySelector('mgt-file-list').addEventListener('itemClick', e => {
// your event handler code goes here
});
Access additional information exposed by the event
Some events emitted by Microsoft Graph Toolkit contain additional information relevant to the event. For example, the itemClick
event, emitted by the File list component, contains information about the file that was clicked in the file list. To see if the particular event contains additional information, see the Events section of the documentation for the corresponding component.
You can access the additional information exposed by an event through the details
property of the event
object passed into your event handler, as shown in the following example.
document.querySelector('mgt-file-list').addEventListener('itemClick', e => {
const clickedFile = e.details;
});
피드백
https://aka.ms/ContentUserFeedback
출시 예정: 2024년 내내 콘텐츠에 대한 피드백 메커니즘으로 GitHub 문제를 단계적으로 폐지하고 이를 새로운 피드백 시스템으로 바꿀 예정입니다. 자세한 내용은 다음을 참조하세요.다음에 대한 사용자 의견 제출 및 보기