diff --git a/content/docs/reference-dom-elements.md b/content/docs/reference-dom-elements.md index 166870968..ee505f68e 100644 --- a/content/docs/reference-dom-elements.md +++ b/content/docs/reference-dom-elements.md @@ -1,6 +1,6 @@ --- id: dom-elements -title: DOM Elements +title: Элементы DOM layout: docs category: Reference permalink: docs/dom-elements.html @@ -14,31 +14,32 @@ redirect_from: - "tips/dangerously-set-inner-html.html" --- -React implements a browser-independent DOM system for performance and cross-browser compatibility. We took the opportunity to clean up a few rough edges in browser DOM implementations. +React реализует независимую от браузера систему DOM для повышения производительности и кроссбраузерной совместимости. Это позволило избавиться от некоторых шероховатостей в браузерных реализациях DOM. -In React, all DOM properties and attributes (including event handlers) should be camelCased. For example, the HTML attribute `tabindex` corresponds to the attribute `tabIndex` in React. The exception is `aria-*` and `data-*` attributes, which should be lowercased. For example, you can keep `aria-label` as `aria-label`. +В React все свойства и атрибуты DOM (включая обработчики событий) должны быть в стиле camelCase. Например, HTML-атрибут `tabindex` соответствует атрибуту `tabIndex` в React. Исключение составляют атрибуты `aria-*` и `data-*`, которые следует писать в нижнем регистре. В частности, вы можете оставить `aria-label` как `aria-label`. -## Differences In Attributes {#differences-in-attributes} -There are a number of attributes that work differently between React and HTML: +## Различия в атрибутах {#differences-in-attributes} + +Есть ряд атрибутов, которые по-разному работают в React и HTML: ### checked {#checked} -The `checked` attribute is supported by `` components of type `checkbox` or `radio`. You can use it to set whether the component is checked. This is useful for building controlled components. `defaultChecked` is the uncontrolled equivalent, which sets whether the component is checked when it is first mounted. +Атрибут `checked` поддерживается компонентами `` типа `checkbox` или `radio`. Он нужен для того, чтобы узнать выбран ли компонент. Это полезно для создания контролируемых компонентов. `defaultChecked` — это неконтролируемый эквивалент, который определяет, выбран ли компонент на момент первого монтирования. ### className {#classname} -To specify a CSS class, use the `className` attribute. This applies to all regular DOM and SVG elements like `
`, ``, and others. +Чтобы указать класс CSS, используйте атрибут `className`. Это относится ко всем обычным элементам DOM и SVG, таким как `
`, `` и т.д. -If you use React with Web Components (which is uncommon), use the `class` attribute instead. +Если вы используете React с веб-компонентами (что встречается редко), используйте вместо этого атрибут `class`. ### dangerouslySetInnerHTML {#dangerouslysetinnerhtml} -`dangerouslySetInnerHTML` is React's replacement for using `innerHTML` in the browser DOM. In general, setting HTML from code is risky because it's easy to inadvertently expose your users to a [cross-site scripting (XSS)](https://en.wikipedia.org/wiki/Cross-site_scripting) attack. So, you can set HTML directly from React, but you have to type out `dangerouslySetInnerHTML` and pass an object with a `__html` key, to remind yourself that it's dangerous. For example: +Свойству `innerHTML` в DOM браузера соответствует `dangerouslySetInnerHTML` в React. Как правило, вставка HTML из кода рискованна, так как можно случайно подвергнуть ваших пользователей атаке [межсайтового скриптинга](https://ru.wikipedia.org/wiki/%D0%9C%D0%B5%D0%B6%D1%81%D0%B0%D0%B9%D1%82%D0%BE%D0%B2%D1%8B%D0%B9_%D1%81%D0%BA%D1%80%D0%B8%D0%BF%D1%82%D0%B8%D0%BD%D0%B3). Таким образом, вы можете вставить HTML непосредственно из React используя `dangerouslySetInnerHTML` и передать объект с ключом `__html`, чтобы напомнить себе, что это небезопасно. Например: ```js function createMarkup() { - return {__html: 'First · Second'}; + return {__html: 'Первый · Второй'}; } function MyComponent() { @@ -48,23 +49,23 @@ function MyComponent() { ### htmlFor {#htmlfor} -Since `for` is a reserved word in JavaScript, React elements use `htmlFor` instead. +Поскольку `for` является зарезервированным словом JavaScript, для определения HTML-атрибута `for` в элементах React вместо него используйте `htmlFor`. ### onChange {#onchange} -The `onChange` event behaves as you would expect it to: whenever a form field is changed, this event is fired. We intentionally do not use the existing browser behavior because `onChange` is a misnomer for its behavior and React relies on this event to handle user input in real time. +Событие `onChange` ведет себя ожидаемо: событие срабатывает при изменении поля формы. Мы намеренно не используем существующее поведение браузера, потому что имя `onChange` плохо передаёт, что происходит на самом деле. Вместо этого, React-реализация `onChange` опирается на браузерное событие для обработки ввода в реальном времени. ### selected {#selected} -The `selected` attribute is supported by `