Skip to content

Commit 5358bae

Browse files
committed
translate DOM Elements page
1 parent 0031db3 commit 5358bae

File tree

1 file changed

+36
-32
lines changed

1 file changed

+36
-32
lines changed

content/docs/reference-dom-elements.md

Lines changed: 36 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -14,27 +14,27 @@ redirect_from:
1414
- "tips/dangerously-set-inner-html.html"
1515
---
1616

17-
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.
17+
React áp dụng hệ thống DOM không phụ thuộc vào trình duyệt để tăng hiệu suất và độ tương thích với nhiều trình duyệt khác nhau. Nhân dịp này, chúng tôi đã chỉnh sửa một vài điểm không tương đồng trong cách làm việc với DOM của các trình duyệt.
1818

19-
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`.
19+
Trong React, thuộc tính DOM va các sự kiện (properties attributes, vd như id, class, value, data-attr, onclick, ...) phải được viết theo camelCase. Ví dụ như attribute `tabindex`, thì trong React là `tabIndex`. Có những ngoại lệ là thuộc tính `aria-*` `data-*` phải được viết chữ thường. Ví dụ `aria-label` vẫn là `aria-label`.
2020

21-
## Differences In Attributes {#differences-in-attributes}
21+
## Sự khác biệt trong các thuộc tính {#differences-in-attributes}
2222

23-
There are a number of attributes that work differently between React and HTML:
23+
Có một số sự khác biệt trong cách thuộc tính hoạt động trong React so với HTML:
2424

2525
### checked {#checked}
2626

27-
The `checked` attribute is supported by `<input>` 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.
27+
Thuộc tính `checked` trong các `<input>` type `checkbox` `radio` được dùng để tạo controlled components, xem mục Controlled Components để biết thêm. `defaultChecked` được dùng để đặt giá trị ban đầu của input, được dùng để tạo Uncontrolled Components.
2828

2929
### className {#classname}
3030

31-
To specify a CSS class, use the `className` attribute. This applies to all regular DOM and SVG elements like `<div>`, `<a>`, and others.
31+
Để đặt CSS class cho các thẻ DOM hay SVG như `div`, `a`, ..., chúng ta sử dụng `className` thay vì `class` như thường lệ do bị đụng với từ khoá của ES6 class.
3232

33-
If you use React with Web Components (which is uncommon), use the `class` attribute instead.
33+
Nếu bạn sử dụng Web Components (trường hợp không phổ biến), thì vẫn dùng `class`.
3434

3535
### dangerouslySetInnerHTML {#dangerouslysetinnerhtml}
3636

37-
`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:
37+
`dangerouslySetInnerHTML` tương đương với `innerHTML` trong DOM. Nhìn chung, việc thay đổi DOM từ Javascript nguy hiểm do mình có thể vô tình để người dùng vô tình bị tấn công bởi [cross-site scripting (XSS)](https://en.wikipedia.org/wiki/Cross-site_scripting). Vì vậy, trong React, bạn phải sử dụng `dangerouslySetInnerHTML` và truyền một object với key là `_html` để đề phòng. Ví dụ:
3838

3939
```js
4040
function createMarkup() {
@@ -48,23 +48,25 @@ function MyComponent() {
4848

4949
### htmlFor {#htmlfor}
5050

51-
Since `for` is a reserved word in JavaScript, React elements use `htmlFor` instead.
51+
Do `for` là một từ khoá trong Javascript, React dùng `htmlFor`.
5252

5353
### onChange {#onchange}
5454

55-
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.
55+
Sự kiện `onChange` hoạt động đúng như tên gọi của nó, được phát ra khi giá trị của `<input>` thay đổi. React dựa vào sự kiện này để xử lý đầu vào từ người dùng ở thời gian thực.
5656

5757
### selected {#selected}
5858

5959
The `selected` attribute is supported by `<option>` components. You can use it to set whether the component is selected. This is useful for building controlled components.
6060

61+
Thuộc tính `selected` được sử dụng trong `<option>` để đánh dấu option nào được chọn trong một `<select>` cho Controlled component.
62+
6163
### style {#style}
6264

63-
>Note
65+
>Ghi chú
6466
>
65-
>Some examples in the documentation use `style` for convenience, but **using the `style` attribute as the primary means of styling elements is generally not recommended.** In most cases, [`className`](#classname) should be used to reference classes defined in an external CSS stylesheet. `style` is most often used in React applications to add dynamically-computed styles at render time. See also [FAQ: Styling and CSS](/docs/faq-styling.html).
67+
>Một vài ví dụ trong tài liệu này sử dụng `style` cho tiện, thực tế **sử dụng thuộc tính `style` tại chỗ không được khuyến khích .** Trong đa phần các trường hợp, [`className`](#classname) nên được dùng cùng với một file CSS rời để style. Thuộc tính `style` thường được dùng trong React để style động ví dụ như người dùng thay đổi màu hoặc font-size bằng một input. Xem thêm [FAQ: Styling and CSS](/docs/faq-styling.html).
6668
67-
The `style` attribute accepts a JavaScript object with camelCased properties rather than a CSS string. This is consistent with the DOM `style` JavaScript property, is more efficient, and prevents XSS security holes. For example:
69+
Thuộc tính `style` nhận vào một object với các thuộc tính CSS ở dạng camelCase. Viết bằng camelCase để tích hợp với key của object trong Javascript, đồng thời mang lại sự nhất quán và chống tấn công XSS. Ví dụ:
6870

6971
```js
7072
const divStyle = {
@@ -77,22 +79,22 @@ function HelloWorldComponent() {
7779
}
7880
```
7981

80-
Note that styles are not autoprefixed. To support older browsers, you need to supply corresponding style properties:
82+
Nhớ rắng styles không có tự động tương thích với các trình duyệt nên bạn phải tự thêm tiếp đầu ngữ vào. Ví dụ:
8183

8284
```js
8385
const divStyle = {
84-
WebkitTransition: 'all', // note the capital 'W' here
85-
msTransition: 'all' // 'ms' is the only lowercase vendor prefix
86+
WebkitTransition: 'all', // nhớ là chữ 'W' được viết hoa
87+
msTransition: 'all' // 'ms' là tiếp đầu ngữ duy nhất được viết thường
8688
};
8789

8890
function ComponentWithTransition() {
8991
return <div style={divStyle}>This should work cross-browser</div>;
9092
}
9193
```
9294

93-
Style keys are camelCased in order to be consistent with accessing the properties on DOM nodes from JS (e.g. `node.style.backgroundImage`). Vendor prefixes [other than `ms`](https://www.andismith.com/blogs/2012/02/modernizr-prefixed/) should begin with a capital letter. This is why `WebkitTransition` has an uppercase "W".
95+
Các thuộc tính css được camelCase để đồng nhất với Javascript, vd `node.style.backgroundImage`. Các tiếp đầu ngữ [ngoài `ms`](https://www.andismith.com/blogs/2012/02/modernizr-prefixed/) phải được bắt đầu bằng một chữ hoa vd như `WebkitTransition`.
9496

95-
React will automatically append a "px" suffix to certain numeric inline style properties. If you want to use units other than "px", specify the value as a string with the desired unit. For example:
97+
React sẽ tự động thêm "px" vào sau các giá trị số. Nếu bạn muốn sử dụng đơn vị khác, hãy dùng kiểu string thay vì number, vd:
9698

9799
```js
98100
// Result style: '10px'
@@ -106,37 +108,39 @@ React will automatically append a "px" suffix to certain numeric inline style pr
106108
</div>
107109
```
108110

109-
Not all style properties are converted to pixel strings though. Certain ones remain unitless (eg `zoom`, `order`, `flex`). A complete list of unitless properties can be seen [here](https://github.com/facebook/react/blob/4131af3e4bf52f3a003537ec95a1655147c81270/src/renderers/dom/shared/CSSProperty.js#L15-L59).
111+
Không phải thuộc tính nào cũng được thêm "px" vào sau. Các thuộc tính không có đơn vị sẽ được giữ nguyên, vd như `zoom`, `order`, `flex`. Tất cả các thuộc tính không có đơn vị có thể được tìm thấy [ở đây](https://github.com/facebook/react/blob/4131af3e4bf52f3a003537ec95a1655147c81270/src/renderers/dom/shared/CSSProperty.js#L15-L59).
110112

111113
### suppressContentEditableWarning {#suppresscontenteditablewarning}
112114

113-
Normally, there is a warning when an element with children is also marked as `contentEditable`, because it won't work. This attribute suppresses that warning. Don't use this unless you are building a library like [Draft.js](https://facebook.github.io/draft-js/) that manages `contentEditable` manually.
115+
Một component có component con được đánh dấu là `contentEditable` sẽ không hoạt động và sẽ được cảnh báo. Thuộc tính này sẽ bỏ đi cảnh báo, nhưng các bạn không cần thiết phải dùng nó trừ khi bạn đang xây dựng một thư viện làm việc trực tiếp với `contentEditable` như [Draft.js](https://facebook.github.io/draft-js/).
114116

115117
### suppressHydrationWarning {#suppresshydrationwarning}
116118

117-
If you use server-side React rendering, normally there is a warning when the server and the client render different content. However, in some rare cases, it is very hard or impossible to guarantee an exact match. For example, timestamps are expected to differ on the server and on the client.
119+
Nếu bạn sử dụng server-side rendering, thông thường sẽ có một cảnh báo khi nội dung được render trên server khác với client. Tuy nhiên, trong một vài trường hợp, rất khó để đảm báo server và client trùng khớp với nhau vd như render timestamp.
118120

119-
If you set `suppressHydrationWarning` to `true`, React will not warn you about mismatches in the attributes and the content of that element. It only works one level deep, and is intended to be used as an escape hatch. Don't overuse it. You can read more about hydration in the [`ReactDOM.hydrate()` documentation](/docs/react-dom.html#hydrate).
121+
Bằng cách đặt `suppressHydrationWarning` `true`, React sẽ không cảnh báo khi nội dung của client và server không khớp nhau. Tuy nhiên `suppressHydrationWarning` chỉ được áp dụng cho một lớp component và chỉ nên sử dụng trong trường hợp bất khả kháng, không nên lạm dụng nó. Xem thêm về Hydration tại [`ReactDOM.hydrate()`](/docs/react-dom.html#hydrate).
120122

121123
### value {#value}
122124

123-
The `value` attribute is supported by `<input>` and `<textarea>` components. You can use it to set the value of the component. This is useful for building controlled components. `defaultValue` is the uncontrolled equivalent, which sets the value of the component when it is first mounted.
125+
Thuộc tính `value` được dùng cho `<input>` `<textarea>`. Bạn có thể dùng `value` để tạo nên Controlled components. Dùng `defaultValue` nếu muốn Uncontrolled components.
124126

125-
## All Supported HTML Attributes {#all-supported-html-attributes}
127+
## Tất cả thuộc tính HTML được hỗ trợ {#all-supported-html-attributes}
126128

127129
As of React 16, any standard [or custom](/blog/2017/09/08/dom-attributes-in-react-16.html) DOM attributes are fully supported.
128130

129-
React has always provided a JavaScript-centric API to the DOM. Since React components often take both custom and DOM-related props, React uses the `camelCase` convention just like the DOM APIs:
131+
Trong React 16, [tất cả](/blog/2017/09/08/dom-attributes-in-react-16.html) thuộc tính DOM đều được hỗ trợ.
132+
133+
React đã luôn được viết với Javascript làm trọng tâm nên hầu hết các thuộc tính DOM đều được viết ở dạng `camelCase` tương tự như DOM API. Ví dụ như:
130134

131135
```js
132-
<div tabIndex="-1" /> // Just like node.tabIndex DOM API
133-
<div className="Button" /> // Just like node.className DOM API
134-
<input readOnly={true} /> // Just like node.readOnly DOM API
136+
<div tabIndex="-1" /> // tương tự node.tabIndex DOM API
137+
<div className="Button" /> // tương tự node.className DOM API
138+
<input readOnly={true} /> // tương tự node.readOnly DOM API
135139
```
136140

137-
These props work similarly to the corresponding HTML attributes, with the exception of the special cases documented above.
141+
Những thuộc tính này gần giống với thuộc tính HTML, với những ngoại lệ liệt kê ở trên.
138142

139-
Some of the DOM attributes supported by React include:
143+
Một vài thuộc tính DOM dc React hỗ trợ như:
140144

141145
```
142146
accept acceptCharset accessKey action allowFullScreen alt async autoComplete
@@ -154,7 +158,7 @@ sizes span spellCheck src srcDoc srcLang srcSet start step style summary
154158
tabIndex target title type useMap value width wmode wrap
155159
```
156160

157-
Similarly, all SVG attributes are fully supported:
161+
Tượng tự, tất cả thuộc tính SVG hoàn toàn được hỗ trợ:
158162

159163
```
160164
accentHeight accumulate additive alignmentBaseline allowReorder alphabetic
@@ -193,4 +197,4 @@ xlinkHref xlinkRole xlinkShow xlinkTitle xlinkType xmlns xmlnsXlink xmlBase
193197
xmlLang xmlSpace y y1 y2 yChannelSelector z zoomAndPan
194198
```
195199

196-
You may also use custom attributes as long as they're fully lowercase.
200+
Bạn có thể sử dụng thuộc tính tự định ra nhưng phải được viết bằng chữ thường.

0 commit comments

Comments
 (0)